Hello DevFourm! I was bored in my class so I decided to make a Timer module!
Features
This module’s backbone is based off the coroutine structure! A.K.A, it wont pause your script and it will run in the background!
The module doesn’t just countdown in the background, you can also connect functions for when it starts (onStart
) and every second tick (onUpdate
)
The module is also very simple to use needing you to require it once!
Usage
First, download the script off the creator store.
Second, place it in an accessible place such as ReplicatedStorage (but I trust you to handle that yourself :D)
Third, require it in your script
local Timer = require(game.ReplicatedStorage.Timer)
Fourth, create the object via .new()
local Timer = require(game.ReplicatedStorage.Timer)
local myTimer = Timer.new(5, function() -- 5 = duration, function() = callback
print("Hello, World")
end)
Fifth, just start the timer via :start()
local Timer = require(game.ReplicatedStorage.Timer)
local myTimer = Timer.new(5, function() -- 5 = duration, function() = callback
print("Hello, World!")
end)
Timer:start()
That’s it! Your timer will run and then after that run the callback function.
You can add connections to parts of the timer shown below:
local Timer = require(game.ReplicatedStorage.Timer)
local myTimer = Timer.new(5, function() -- 5 = duration, function() = callback
print("Hello, World!")
end)
-- Called on Timer:start()
myTimer.onStart:Connect(function()
print("Started!")
end)
-- Called every second
myTimer.onUpdate:Connect(function(timeRemaining)
print("Time left:" .. timeRemaining)
end)
myTimer:start()
I hope you enjoy my small script I made for fun!
As always, happy scripting! :3