You can verify if the script is running by checking for the resource state:
if GetResourceState('ts-persistence') == 'started' then
-- Script is running
end
Exports
DeleteVehicleEntity
Deletes the vehicle entity from the game world, but keeps its data in the database.
exports['ts-persistence']:DeleteVehicleEntity(vehicleId)
| Argument | Type | Description |
|---|
vehicleId | string | The unique persistence ID of the vehicle. |
GetAllVehicles
Get a list of all vehicles currently loaded by the persistence system.
local vehicles = exports['ts-persistence']:GetAllVehicles()
Returns:
table: A dictionary of all active vehicles.
DoesVehicleExistInDb
Check if a vehicle exists in the database.
local exists = exports['ts-persistence']:DoesVehicleExistInDb(vehicleId)
| Argument | Type | Description |
|---|
vehicleId | string | The persistence ID of the vehicle. |
Returns:
boolean: true if it exists, false otherwise.
Reload
Reload all vehicles from the database and refresh the system.
exports['ts-persistence']:Reload()
UpdateVehiclePos
Update the position of a persistent vehicle in memory.
exports['ts-persistence']:UpdateVehiclePos(vehicleId, coords, heading)
| Argument | Type | Description |
|---|
vehicleId | string | The persistence ID of the vehicle. |
coords | vector3 | The new coordinates. |
heading | number | The new heading. |
UnloadAllVehicles
Deletes all persistent vehicle entities from the game world (does not remove their data from the database).
exports['ts-persistence']:UnloadAllVehicles()
SetVehicleDeleteAt
Set a Unix timestamp for when the vehicle should be automatically deleted from the database.
exports['ts-persistence']:SetVehicleDeleteAt(vehicleId, timeTimestamp)
| Argument | Type | Description |
|---|
vehicleId | string | The persistence ID of the vehicle. |
timeTimestamp | number | The Unix timestamp for deletion. |
DeleteVehicleFromDB
Delete a vehicle from the persistence database using its ID.
exports['ts-persistence']:DeleteVehicleFromDB(vehicleId)
| Argument | Type | Description |
|---|
vehicleId | string | The persistence ID of the vehicle to delete. |
DeleteVehicleFromDBByPlate
Delete a vehicle from the persistence database using its plate.
exports['ts-persistence']:DeleteVehicleFromDBByPlate(plate)
| Argument | Type | Description |
|---|
plate | string | The plate of the vehicle to delete from the database. |
ForgetVehicle
Forget the persistence entry for a vehicle, completely removing it from the persistent system and the database.
local success = exports['ts-persistence']:ForgetVehicle(vehicleId, plate, deleteEntity)
| Argument | Type | Description |
|---|
vehicleId | string | nil | The persistence ID of the vehicle (optional if plate is provided). |
plate | string | nil | The plate of the vehicle (optional if vehicleId is provided). |
deleteEntity | boolean | nil | If true and the vehicle is currently spawned, its entity will also be deleted from the world. Defaults to false. |
Returns:
boolean: true if successful, false otherwise.
Last modified on March 11, 2026