Skip to main content

FiveM Lua Wait(0) or Wait(1000): choose by behavior

Written by FiveMCoach · AI-assisted editorial guide; official sources checked

Last updated

FiveM Lua Wait(0) vs Wait(1000): choose the right loop

An evergreen developer guide to separating per-frame work from periodic work, keeping loops cooperative, and reviewing a timing change without hiding broken behavior.

Quick answer

Use Wait(0) for client work that must run every frame. Use a positive delay for work that can tolerate a pause. Choose from the behavior you need to preserve, then test that behavior; a lower activity number alone does not prove the change is correct.

On this page

Evergreen practical guide. Official references checked on 16 September 2026. AI-assisted FiveMCoach editorial content. This article concerns Lua client scheduling, not a measured optimization of your resource.

What does Wait actually change?

Citizen.Wait yields the current coroutine. Zero resumes on the next game tick; a positive value specifies an approximate delay in milliseconds. Client ticks depend on frames, so a wait is not an exact timer. Cfx.re recommends zero for work required every frame.

Run yielding code in an appropriate coroutine, such as the handler created by Citizen.CreateThread. A new thread does not make a busy infinite loop harmless: the documented warning is that a loop without a yield can freeze the game. Check every branch, including error and early-return paths.

How do you decide whether a loop can wait longer?

Write one sentence describing the observable requirement before touching the delay. For example: “This display must remain visible while the mode is active,” or “This diagnostic note may update once a second.” These are proposed requirements, not claims about a particular native function. Check the documentation of the native you actually call.

Next, list what the loop does: presentation, state lookup, expensive calculation, or a business action. If these jobs have different timing needs, review them separately. Do not make an entire mixed loop slower simply because its least urgent calculation can wait.

Agree on a maximum acceptable reaction delay for periodic behavior. This is a product decision to test, not a universal FiveM setting. Write the acceptance case before implementation so a smoother performance graph cannot hide a missed interaction.

Can you try a small example without changing gameplay?

On a local development server, create a separate resource named wait_probe. Its resource manifest loads only one client script. This sample has no network events, database writes, rewards or player-state changes.

Create fxmanifest.lua:

fx_version 'cerulean'
game 'gta5'
client_script 'client.lua'

Create client.lua:

CreateThread(function()
    for sample = 1, 3 do
        Wait(1000)
        print(("[wait_probe] sample %d of 3"):format(sample))
    end
end)

Use the server console to run refresh, then ensure wait_probe, and inspect the client F8 console. The intended result is three numbered messages followed by no further sample output. The loop is deliberately bounded so it does not create a permanent logging task. See the resource command guide if the resource is not discovered.

If nothing appears, confirm the folder, manifest filename and client.lua spelling, then inspect startup errors before editing the delay. After the exercise, stop the resource with stop wait_probe. Do not add it to your production startup configuration.

Example verification: the files and control flow were reviewed against the documentation. The example was not executed inside FiveM, and no timing or performance result is claimed. Use it as a development exercise, not a benchmark.

How should you review a real timing change?

Keep the original version available. Test the inactive state, entry into the active state, normal use, exit and re-entry. Repeat at more than one client frame rate where practical. Record the actual behavior rather than only whether the console stayed quiet.

When profiling is relevant, Cfx.re documents profiler record 500, profiler status and profiler view. Capture the same scenario before and after your change and inspect the relevant thread. The profiler guide explains how captures expose resource and script work; it does not promise that changing a wait fixes that work.

Stop the rollout if the changed version misses the agreed behavior. Restore the previous implementation and isolate the job that can safely run less often. For broader diagnosis, use the FiveM performance playbook; for a structured foundation, explore the Lua curriculum.

Checklist
  • Write the observable requirement for each loop.
  • Separate presentation and periodic work during review.
  • Check every loop branch for a reachable yield.
  • Keep the previous implementation available.
  • Test entry, exit and re-entry as well as steady use.
  • Record behavioral results before claiming an improvement.
Need Choice Check
Every client frame Wait(0) API timing needs
Periodic output Positive delay Useful update rate
Mixed jobs Separate first Strictest timing need
Common mistakes

Do not replace every zero wait with the same positive number. Do not assume a quieter loop still performs the required job. Keep temporary logging out of the final measurement, and stop testing a changed version if it misses the agreed interaction. Restore the known version before investigating the next hypothesis.

FiveMCoach perspective

Our recommendation is to approve timing changes with two pieces of evidence: the behavior still works and the measured cost is appropriate for that behavior. Treat a delay as part of the feature contract. A smaller number in a tool is insufficient when the player can no longer complete the action.

Does Wait pause every resource on the server?
It yields the current coroutine, not every resource. This guide uses a client-side example; do not interpret its frame-related discussion as a server-wide scheduling guarantee.
Is a one-second wait guaranteed to resume at exactly one second?
No. The documented delay is approximate. Avoid using the sample as evidence of precise timing, and define the behavior your real feature must satisfy.
Can I claim an optimization after trying this sample?
No. The sample only illustrates bounded periodic work. A performance claim needs measurements from the actual resource and a check that the required behavior still works.

Ready for the next step?

Stop guessing. Get a concrete plan for your server and move with confidence.

Written by
FiveMCoach · AI-assisted editorial guide; official sources checked
A FiveMCoach contributor responsible for this guide's visible content.