Timer.new
Creates a repeating timer. Configure Interval, RepetitionCount and OnElapsed, then set Enabled to true.
Syntax
Timer.new() -> any
Parameters
This function takes no parameters.
Returns
| Type | Description |
|---|---|
any | The value produced by the call. |
Description
Timer.new is part of the Timer library. Timer, Stopwatch and Duration objects driven by the VM scheduler.
Each call creates or returns a fresh object or value that you can store and pass to other functions.
Example
local timer = Timer.new()
timer.Interval = 1
timer.RepetitionCount = 3
timer.OnElapsed:Connect(function()
print("tick")
end)
timer.Enabled = true
Notes
- Timer callbacks run on the executor scheduler; disable or destroy timers when they are finished.