This is a timer module which can be used with Luau to make countdowns.
- You can copy the module in shared folder and put to your project.
- Add this to your [dependencies],
TimerModule = "aerodymier/timermodule^@0.1.2"
and then run wally install
in your current directory.
- You can get this model (https://www.roblox.com/library/9820188808/TimerModule) and drag that to your game.
Another option is using the module file in Releases section, there's also an example place file.
This module has two modes, one mode lets you set a goal with an unix timestamp and other one lets you set a goal with human readable format.
You can create a new Timer with the only parameter being a DateTime
type:
local newTimer = Timer.new(DateTime.fromUnixTimestamp(1672531201))
You can also create a new Timer with human readable format. That means you just type the date in an order.
local newTimer = Timer.new("2023 11 1 12 0 1") -- YYYY MM DD HH MM SS
This part depends on how you want to implement it however I generally use it with a loop. calculateTime()
gets a DateTime
type of parameter and that's where the module will count from.
while true do
task.wait(1)
local dt = DateTime.now()
local formattedText: string | boolean = newTimer:calculateTime(dt)
if typeof(formattedText) == "boolean" then
print("Ended!")
break
else
print(formattedText)
end
end
Human readable format works similar, I used universal time here but you can get client's timezone and calculate the time with that if you want.
while true do
task.wait(1)
local dt = DateTime.now()
local formattedText: string | boolean = newTimer:calculateTime(dt:FormatUniversalTime("YYYY MM DD HH mm ss", "en-us"))
if typeof(formattedText) == "boolean" then
print("Ended!")
break
else
print(formattedText)
end
end
Module returns a bool type when countdown ends and starts to count in reverse when goal is before the current date. Prints look like this:
7 months, 30 days, 1 hour, 59 minutes, 13 seconds
Module respects singular numbers and uses them with singular words.
There are examples for both methods in src/Examples folder.
If you face any issues while using this model consider opening an issue or making a PR.