Skip to main content
TRACK B·BUILD REAL PRODUCTS·Verified June 2026 · Lua 5.4 · ox_lib 3.x
Learning with an AI assistant?
Copies this lesson plus 2026 ground rules (no lua54 'yes', Cfx.re Portal, correct callback signatures) as a ready-to-paste mentor prompt.

Vehicles: spawn, modify, clean up

Vehicles are the most common entity you will work with in FiveM. Garage scripts, dealerships, police cruisers, test commands -- they all start with spawning a car and putting the player in it. This lesson covers the full cycle: stream the model in, spawn the car, customize it, put the player inside, and delete it cleanly when the timer runs out.

You'll ship
A /testvehicle command that spawns a car, sets a custom plate and color, warps the player into the driver seat, and auto-deletes the car after 60 seconds.
Time
~30 minutes
You'll learn
The model request-and-poll pattern, joaat hashes, CreateVehicle and its network ownership flags, TaskWarpPedIntoVehicle seat indexes, the vehicle color table, and SetTimeout closure cleanup.
BEFORE YOU START

Build it

Make the resource folder

The server has one folder for this lesson.

Inside your server's resources folder, create this folder:

code
resources/qu_vehicles_spawn_modify_store

Create the files

Every file named in the manifest exists.

Create this exact file layout:

code
resources/qu_vehicles_spawn_modify_store/
fxmanifest.lua
client.lua

Write fxmanifest.lua

FiveM knows which files to load.

Open fxmanifest.lua and paste this:

code
fx_version 'cerulean'
game 'gta5'

client_script 'client.lua'

Spawning a car and warping the player both happen on the client, so this resource has a client_script and no server_script. Older tutorials add a lua54 'yes' line here. As of June 2025 that setting is deprecated and ignored: Lua 5.4 is now the only Lua runtime, so you leave it out.

Write the lesson code

The topic is now represented by runnable code.

Open client.lua and paste this. The lines are spread out on purpose so the next section can walk through them one at a time:

code
local testVehicle

local function loadModel(model)
if not IsModelInCdimage(model) or not IsModelAVehicle(model) then
    return false
end

RequestModel(model)
local deadline = GetGameTimer() + 5000
while not HasModelLoaded(model) do
    if GetGameTimer() > deadline then return false end
    Wait(0)
end
return true
end

RegisterCommand('testvehicle', function()
if testVehicle and DoesEntityExist(testVehicle) then
    DeleteEntity(testVehicle)
end

local model = joaat('sultan')
if not loadModel(model) then
    print('[qu_vehicles_spawn_modify_store] invalid vehicle model or load timeout')
    return
end

local ped = PlayerPedId()
local c = GetEntityCoords(ped)
testVehicle = CreateVehicle(model, c.x + 3.0, c.y, c.z, GetEntityHeading(ped), true, false)

SetVehicleNumberPlateText(testVehicle, 'QUCAR')
SetVehicleColours(testVehicle, 12, 12)
TaskWarpPedIntoVehicle(ped, testVehicle, -1)

SetModelAsNoLongerNeeded(model)
print('[qu_vehicles_spawn_modify_store] spawned sultan')

local spawned = testVehicle
SetTimeout(60000, function()
    if spawned and DoesEntityExist(spawned) then
        DeleteEntity(spawned)
        print('[qu_vehicles_spawn_modify_store] auto-deleted')
    end
end)
end, false)

Start and test it

The expected proof appears in the F8 client console.

Open server.cfg and add this line:

code
ensure qu_vehicles_spawn_modify_store

Save, then run this in the server console:

code
restart qu_vehicles_spawn_modify_store

Join the server, open the F8 console, and run:

code
/testvehicle

A Sultan appears beside you, you are dropped into the driver seat, the plate reads QUCAR, and the body is matte black. Sixty seconds later the car vanishes.

Keep reading the full lesson

Sign in to start, then unlock every step of this lesson and the full FiveM School with a membership.

Still ahead in this lesson
  • How it works
  • If something went wrong
  • What you can do now
  • Try it yourself

The remainder of Vehicles: spawn, modify, store is available to FiveM School members.