Skip to main content

Timer

The Timer utility is a global class for scheduling delayed or repeating callbacks. It provides both classic timer-based control and coroutine-style asynchronous flows for scripting convenience. All timer functions are available on both server and client.


Methods

MethodParametersReturn TypeAuthorityDescription
Timer.SetNextTickCallback: functionvoidBothSchedules a one-time callback to run on the next engine tick.
Timer.SetTimeoutCallback: function, Delay: numbernumberBothSchedules a one-time callback to execute after a delay (in milliseconds). Returns a timer ID.
Timer.SetIntervalCallback: function, Interval: numbernumberBothRuns the callback repeatedly every Interval milliseconds until cleared. Returns a timer ID.
Timer.ClearTimeouttimerID: numbervoidBothStops a one-shot or repeating timer by ID.
Timer.ClearIntervaltimerID: numbervoidBothAlias of Timer.ClearTimeout. Stops a timer by ID.
Timer.PausetimerID: numbervoidBothPauses a currently active timer.
Timer.ResumetimerID: numbervoidBothResumes a paused timer.
Timer.IsValidtimerID: numberbooleanBothReturns true if a timer is still active and not cleared or expired.
Timer.IsPausedtimerID: numberbooleanBothReturns true if the timer is currently paused.
Timer.GetElapsedTimetimerID: numbernumberBothReturns how much time (in milliseconds) has passed since the timer started or last ran.
Timer.GetRemainingTimetimerID: numbernumberBothReturns the number of milliseconds left before the next callback execution.
Timer.InvalidatetimerID: numbervoidBothManually invalidates a timer handle so it will not run again, even if not cleared.
Timer.HasHandletimerID: numberbooleanBothReturns true if a timer has a valid handle, even if paused.
Timer.ResetElapsedTimetimerID: numbervoidBothRestarts a timer with the same delay and arguments, resetting its elapsed time.
Timer.DelayworldContext: HPlayer/HWorld, seconds: number, Callback: functionvoidBothCoroutine-safe delay that pauses execution for the given seconds, then runs the callback.
Timer.CreateThreadCallback: functionvoidBothRuns a Lua function as a coroutine thread, similar to FiveM behavior.
Timer.WaitwaitTime: numbervoidBothCoroutine-only delay (must be called from inside Timer.CreateThread). Pauses the thread for the given milliseconds.

Examples

Delayed Execution

// Timer scheduling is handled via Lua or JavaScript scripting.

Repeating Interval with Pause/Resume

// Interval scheduling is handled via Lua or JavaScript scripting.

Coroutine Threads

// Coroutine threads are a Lua-only feature.

tip

This is the preferred method of running a continuous loop versus using a thread. Always call Timer.ClearInterval in the global onShutdown function to prevent leaked callbacks.