Skip to main content

Documentation Index

Fetch the complete documentation index at: https://docs.toine.me/llms.txt

Use this file to discover all available pages before exploring further.

When a vehicle is deleted by an admin command or stored in a garage, you may need to remove it from persistence so it doesn’t respawn later. Here are a few examples of how to accomplish this using the ForgetVehicle export.

Delete Vehicle Command (/dv)

When you delete a vehicle manually using a command, you should remove it from persistence so it is no longer restored automatically.
Add this line: exports['ts-persistence']:ForgetVehicle(nil, QBCore.Functions.GetPlate(veh))
resources/[qb]/qb-core/client/events.lua
    RegisterNetEvent('QBCore:Command:DeleteVehicle', function()
        local ped = PlayerPedId()
        local veh = GetVehiclePedIsUsing(ped)
        if veh ~= 0 then
            -- Add this line to forget the vehicle
            exports['ts-persistence']:ForgetVehicle(nil, QBCore.Functions.GetPlate(veh))
            
            SetEntityAsMissionEntity(veh, true, true)
            DeleteVehicle(veh)
        else
            local pcoords = GetEntityCoords(ped)
            local vehicles = GetGamePool('CVehicle')
            for _, v in pairs(vehicles) do
                if #(pcoords - GetEntityCoords(v)) <= 5.0 then
                    -- Add this line to forget the vehicle
                    exports['ts-persistence']:ForgetVehicle(nil, QBCore.Functions.GetPlate(v))
                    
                    SetEntityAsMissionEntity(v, true, true)
                    DeleteVehicle(v)
                end
            end
        end
    end)

Sync door lock status changes

When your keys script locks/unlocks a vehicle, also update ts-persistence with: exports['ts-persistence']:UpdateDoorStatus(vehicle, status)
  • status = 2 to lock
  • status = 1 to unlock
Example with lfKeys (same integration pattern for any keys script):
if locked == 1 or locked == 0 then
    -- your lock logic
    exports['ts-persistence']:UpdateDoorStatus(vehicle, 2)
elseif locked == 2 then
    -- your unlock logic
    exports['ts-persistence']:UpdateDoorStatus(vehicle, 1)
end
Important: the lfKeys snippet is only a reference.
For any other keys script, call UpdateDoorStatus right after the lock status changes.

Adding to a Garage System

If you are adding this script to your server, you will need to call the export when a vehicle is successfully stored in the garage so that it is no longer restored from persistence. Here is an example of how it looks in the default qb-garages script when a vehicle is deposited:
Add this line: exports['ts-persistence']:ForgetVehicle(nil, plate)
resources/[qb]/qb-garages/client/main.lua
    local function DepositVehicle(veh, data)
        local plate = QBCore.Functions.GetPlate(veh)
        QBCore.Functions.TriggerCallback('qb-garages:server:canDeposit', function(canDeposit)
            if canDeposit then
                local bodyDamage = math.ceil(GetVehicleBodyHealth(veh))
                local engineDamage = math.ceil(GetVehicleEngineHealth(veh))
                local totalFuel = exports[Config.FuelResource]:GetFuel(veh)
                TriggerServerEvent('qb-mechanicjob:server:SaveVehicleProps', QBCore.Functions.GetVehicleProperties(veh))
                TriggerServerEvent('qb-garages:server:updateVehicleStats', plate, totalFuel, engineDamage, bodyDamage)
                
                -- Add this line to forget the vehicle from persistence
                exports['ts-persistence']:ForgetVehicle(nil, plate)
                
                CheckPlayers(veh)
                if plate then TriggerServerEvent('qb-garages:server:UpdateOutsideVehicle', plate, nil) end
                QBCore.Functions.Notify(Lang:t('success.vehicle_parked'), 'primary', 4500)
            else
                QBCore.Functions.Notify(Lang:t('error.not_owned'), 'error', 3500)
            end
        end, plate, data.type, data.indexgarage, 1)
    end
Last modified on April 1, 2026