tw.waiter
Side: Shared (Client + Server)
Utility for waiting until a condition becomes true, with timeout support.
Functions
tw.waiter.exec(condition, on_tick?, poll_interval?, timeout_ms?)
Blocks the current thread until condition() returns true, or until the timeout is reached.
| Parameter | Type | Default | Description |
|---|---|---|---|
condition | function | — | Function called repeatedly. Must return true to stop waiting |
on_tick | function? | nil | Optional function called each tick while waiting |
poll_interval | integer? | 0 | Milliseconds between each condition check |
timeout_ms | integer? | 5000 | Maximum wait time in milliseconds. 0 = no timeout |
Returns: boolean — true if the condition was met, false if the timeout was reached.
Examples
Wait for a model to load
lua
RequestModel(model_hash)
local loaded = tw.waiter.exec(function()
return HasModelLoaded(model_hash)
end)
if not loaded then
print("Model failed to load within 5 seconds")
endCustom timeout and poll interval
lua
-- Check every 100ms, timeout after 10 seconds
local ready = tw.waiter.exec(function()
return IsPlayerReady()
end, nil, 100, 10000)With on_tick callback
lua
-- Draw text while waiting for a door to open
local opened = tw.waiter.exec(function()
return IsDoorOpen(door_id)
end, function()
tw.text3d.draw(door_coords, "Opening...")
end)No timeout (wait forever)
lua
-- Wait indefinitely until the condition is true
tw.waiter.exec(function()
return HasCollisionLoadedAroundEntity(entity)
end, nil, 0, 0)Notes
- Default timeout is 5000ms (5 seconds). If the condition is not met within this time, the function returns
false. - Set
timeout_msto0to wait indefinitely (use with caution). - The
on_tickcallback is useful for drawing UI elements (text, markers) while waiting.

