Loading content...
Timer
An async countdown timer with pause / play / restart / forceEnd and an on-end callback.
An async countdown timer with pause / play / restart / forceEnd and an on-end callback.
lib.timer(time, onEnd?, async?) creates and starts a countdown of time ms and returns a
Timer handle. With async = false (default) the call blocks until the timer ends; with
async = true it returns immediately.
local cooldown = lib.timer(5000, function()
lib.print.info('Cooldown over')
end, true)| Method | Returns | Description |
|---|---|---|
pause() | — | Freeze the remaining time. |
play() | — | Resume a paused timer. |
isPaused() | boolean | Whether it's paused. |
getTimeLeft(format?) | number / { ms, s, m, h } | Time left; a unit ('ms'/'s'/'m'/'h') returns a number, no arg returns all units. |
forceEnd(triggerOnEnd?) | — | End now; onEnd fires unless you pass false. |
restart(async?) | — | Reset to the initial time and restart. |
pause()play()isPaused()booleangetTimeLeft(format?)number / { ms, s, m, h }'ms'/'s'/'m'/'h') returns a number, no arg returns all units.forceEnd(triggerOnEnd?)onEnd fires unless you pass false.restart(async?)time and restart.cooldown.pause()
Wait(2000)
cooldown.play()
local left = cooldown.getTimeLeft('s')
cooldown.forceEnd(false) -- end now, skip onEndA non-async timer blocks its coroutine — call it inside a CreateThread or pass async = true. Frame resolution (~16 ms): don't use it for ~50 ms delays (use Wait). To cancel for good, forceEnd(false) and don't restart.