Docs / API reference / timer
timer
Run a function later, or repeatedly. Timers run on the script's own clock inside the frame budget.
since 1.0 no permission needed
At most 64 timers per script. All timers are cancelled when the script stops. A timer callback has the same 3 ms budget as any other callback, so keep it short.
Reference# timer.after# since 1.0 timer .after (seconds: number, fn: function ): integerCalls fn once after the delay.
Parameter Type Description secondsnumberDelay before the call. fnfunctionCalled once.
Returns Description integerA timer id for timer.cancel.
lua Copy
timer .after (3 , function () log .info ("three seconds later" ) end )timer.every# since 1.0 timer .every (seconds: number, fn: function ): integerCalls fn repeatedly. An interval below 0.02 s is raised to 0.02.
Parameter Type Description secondsnumberInterval. At least 0.02. fnfunctionCalled each interval.
Returns Description integerA timer id.
lua Copy
local id = timer .every (10 , function () store .save () end )timer.cancel# since 1.0 timer .cancel (id: integer): booleanParameter Type Description idintegerA timer id.
Returns Description booleantrue when a timer was cancelled.
API 1.1 · source docs-src/api/timer.json