How can I make multiple timers that continue ticking after the player left the game?

I know how to make a timer that continues to tick down after the player left the game using AlvinBlox’s Daily Reward tutorial. However, I had some issues implementing a feature that would allow me to store multiple timers.

I don’t know if anyone has played Pet Simulator X. If you have then you probably used the “Dark Matter Machine” to convert rainbow pets. Thats basically what I’m trying to do here. I’m trying to store multiple items with each of them having a different amount of time.

I also am curious on how I would know if one of them finished so I can trigger an event to the client!

1 Like

You can probably save multiple timers in a dictionary using datastore if that makes sense. Assuming that the method of saving the starting time is based on time passed since unix epoch.

For example:

local timers = {
    thisItem = 1704304034 -- os.time()
    thisOtherItem = 1704300034
} -- this dictionary is saved in datastore.

print(os.time() - timers.thisItem) -- (CurrentTimeStamp - PreviousTimeStamp) = 65 seconds ago
1 Like

if I was you i would use os.time()
for example save the current time in a variable

local value = os.time()

then to get the time since then just do

print(os.time() - value)

edit: woops someone responded at the exact same time

2 Likes

@XxprofessgamerxX @lordsugarv2 Both of these methods would probably work. However, how can I tell how much time is left in the timer, since Unix Epoch?

local timer = os.time() + 60 – create a timer has a value 60 seconds in the future
print(timer - os.time()) – prints the time left on the timer

if the value is negative or 0 then the timer has complete

Just constantly change the label on text to say

local endTime = os.time() + 60 – ur unix epoch value
label.Text = math.max(timer - os.time(), 0) – makes it so the timer stops when it reaches 0

Sorry! I figured out how! Thanks for your help.

1 Like

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.