DocsLua scripting
Threads, Wait & timers
Run code over time without blocking the server.
lua
CreateThread(function()
while true do
Wait(60000) -- 60 s, without blocking the server
print(#GetPlayers() .. ' players online')
end
end)
SetTimeout(5000, function() print('5 seconds later') end)Citizen.CreateThread, Citizen.Wait, Citizen.SetTimeout and Citizen.Trace exist too (FiveM-compatible).
#Rules
- Use
Wait()insideCreateThread.Wait(0)waits until the next server tick. - Threads stop by themselves when the resource stops.
GetGameTimer()gives milliseconds since the server started - good for measuring time.
Warning
A loop without Wait() freezes the whole server.
Last updated 2026-12-06