A lightweight and efficient countdown/count-up timer module for Roblox, written in Luau. It supports starting, pausing, resetting, and stopping timers with event-driven notifications.
- Count up or down from a specified time
- Event-driven:
Began
,Paused
,Ended
signals - Optimized and strict-typed using Luau
- Clean lifecycle management with
Destroy
Add TimerService
as a ModuleScript in ReplicatedStorage or any preferred location in your Roblox game.
local TimerService = require(path.to.TimerService)
local timer = TimerService.new(5, true) -- 5 seconds, counting up
Parameters:
End: number?
– Target time in seconds (default: 1)Add: boolean?
– If true, timer counts up toEnd
. If false, counts down (default: true)
timer:Start()
timer:Pause()
timer:Stop()
timer:Reset()
timer:Destroy()
Timers are event-driven and expose these signals:
Event | Description |
---|---|
Began |
Fired when the timer starts |
Ended |
Fired when the timer completes |
Paused |
Fired when the timer is paused |
timer.Began:Connect(function(startTime)
print("Timer began at:", startTime)
end)
timer.Ended:Connect(function()
print("Timer ended!")
end)
timer.Paused:Connect(function(currentTime)
print("Timer paused at:", currentTime)
end)
Creates a new Timer instance.
Starts the countdown/count-up.
Pauses the timer (retains state).
Stops and resets the timer.
Resets the timer to its initial state.
Cleans up events and memory (use before discarding the timer).
export type TimerMeta = {
read __index:TimerMeta;
read new:typeof(Timer_new);
read Destroy:typeof(Timer_Destroy);
read Start:typeof(Timer_Start);
read Stop:typeof(Timer_Stop);
read Pause:typeof(Timer_Pause);
read Reset:typeof(Timer_Reset);
}
export type TimerObj = {
_add:boolean;
_time:number;
_end:number;
_event:RBXScriptConnection?;
_began:BindableEvent;
_ended:BindableEvent;
_paused:BindableEvent;
Began:RBXScriptSignal;
Ended:RBXScriptSignal;
Paused:RBXScriptSignal;
}
used chatgpt to generate the README, it should be accurate enough for you to understand it properly