Countdown from os.time()

I have a Datastore and it stores the os.time() of when a chest was opened. And a local script will run to use that os.time() to countdown how would I do this?

1 Like

I would save that os.time() in a Value inside the player, and have a local script compare current os.time() with that of the value.

I have it saved inside a value using Datastore Service. When the player joins the game if they have never opened the chest a value inside of Player will be set to 0 and if they have it’ll obviously have a os.time() for value. Although i wanna make it countdown from 8 hours which is the cooldown period to open the chest again.

Why do you need to use os.time()? The use of tick() would be more fitting for this example.

1 Like

You can’t use tick() because it is the local time for the server, not UTC time, so a timestamp generated by one server is not valid on all other servers.

As for how to count down, what part are you asking about exactly? Current os.time() - storedOStime is the time elapsed in seconds. Subtract that from 8*3600, and if it’s a positive result, that’s how many seconds left until you can open it again.


Well, yes, that could potentially work. os.time will return time since unix epoch. Here is a quick mock-up:

--storedTime = set datastore for initial stored time
local elapsedTime = storedTime - os.time()
1 Like

When you open the chest an 8 hour countdown should begin. I’m stuck with how to store the countdown so when they leave game for a hour it’ll say 7:xx:xx etc.