The Timer module provides a simple and efficient way to manage countdown timers in the game. It allows you to create timers that can count down from a specified duration, trigger events when the time changes, and notify when the timer has ended.
- Create a new timer with a specified countdown duration.
- Start the timer and track the elapsed time.
- Receive updates on the remaining time through events.
- Cleanly destroy the timer and release resources.
To use the Timer module, follow these steps:
-
Create a Timer Instance:
local Timer = require(path.to.Timer) local myTimer = Timer.new(60) -- Create a timer for 60 seconds
-
Start the Timer:
myTimer:Start() -- Start the countdown
-
Connect to Time Changed Event:
myTimer.TimeChanged:Connect(function(remainingTime) print("Time remaining: " .. remainingTime) end)
-
Connect to Timer Ended Event:
myTimer.TimerEnded:Connect(function() print("Timer has ended!") end)
-
Destroy the Timer:
myTimer:Destroy() -- Clean up when done
Here is a complete example of using the Timer module: