Timer
The Timer class allows for code to run periodically at specified intervals.
local timer = Timer.new(2)
timer.onTicked:Connect(function(tickDelta)
print("Tock")
end)
timer:start()
Properties
onTicked
Timer.onTicked:
Signal
<
timerDelta:
number
>
The event which is fired every time the timer hits its interval.
Functions
new
Creates a new timer.
is
Timer.
is
(
self:
any
) →
boolean
Returns true
if the given object is a Timer.
start
Timer:
start
(
) →
(
)
Starts the timer. Will do nothing if the timer is already running.
timer:Start()
tickDelta
Timer:
tickDelta
(
) →
number
Returns the timer tick delta.
print(timer:tickDelta())
ticked
Timer:
ticked
(
) →
boolean
Returns a boolean indicating whether or not the timer ticked.
Here's an alternative variant to just listening to [Timer.onTicked]:
local timer = Timer.new(1)
while true do
if timer:ticked() then
warn("we do something every 1~ second")
end
timer.onTicked:Wait()
end
startNow
Timer:
startNow
(
) →
(
)
Starts the timer and fires off the Timer.onTicked signal immediately. Will do nothing if the timer is already running.
timer:startNow()
stop
Timer:
stop
(
) →
(
)
Stops the timer. Will do nothing if the timer is already stopped.
timer:stop()
interval
Timer:
interval
(
) →
number
Returns the timer's tick interval.
running
Timer:
running
(
) →
boolean
Returns true
if the timer is currently running.
if timer:running() then
-- Do something
end
destroy
Timer:
destroy
(
) →
(
)
Destroys the timer. This will also stop the timer.