Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
1

How Can I Create A Countdown Until A Certain Time?

Asked by 4 years ago

Hello! I want to create a GUI which has a countdown until a certain time but it counts down to a certain time in irl. Such as Jailbreak events. They have a continuous countdown until a certain time. I also want it that when the countdown finishes, something happens. Can someone please help me?

1 answer

Log in to vote
0
Answered by 4 years ago
Edited 4 years ago

What you need is os.time, it gives you an actual date unlike tick.

This Spooks's (Epic person btw) video explains how to use it: https://www.youtube.com/watch?v=owoLIhysMDo

[SEE EDIT] os.time depends on timezones though, so make sure to send the time to the event to all the clients through a RemoteEvent, to use it and make the countdown.

That also means it's gonna give you a time you weren't expecting if you are running it on an actual server (not in Studio) so make sure you keep that in mind.

Try determining the actual time of the event in regards to the time of Roblox's server or better yet your own time, for example if you wanna make it 1 hour from now, it will go something like this:

local oneHourLater = os.time() + 3600 -- os.time gives you the time since 1/1/1970 in seconds according to your location, sounds pretty specific and neat right? it's called Unix Time
-- and 3600 is how many seconds there are in an hour (60 secs * 60 mins)

Now you should run this in the command bar and store what you get in your game script and check if it's time for the event (a very basic os.time >= the value you got)

Hopefully, this clears it up a bit, the reason why you don't put this code directly in your game script is that this will make it happen after the server has aged one hour not the exact time you want.

As to how to compensate for Roblox's different timezone, I am not sure.

Feel free to ask me anything if it's not clear enough.

EDIT: I am extremely sorry, os.time doesn't depend on timezones, it only returns GMT time. So if you want an event that will happen at for example 1 hour from GMT time rn, all you have to do is the same as above.

If you want a countdown, you will just use

secondsTillEvent = oneHourLater - os.time() -- which will work on completly all PCs and servers around the world
if secondsTillEvent < 0 then print("it's the big day") end

Just again, don't forget to save that time separately and not at run-time.

0
I think I got it thx. Aiden_12114 79 — 4y
0
No problem. Again, feel free to ask if anything's not clear. GGRBXLuaGG 417 — 4y
Ad

Answer this question