So I have this local script on a surface gui parent to Player GUI and Adornee to a part
local function toHMS(s)
return string.format("%02i:%02i:%02i", s/60^2, s/60%60, s%60)
end
local Event1 = script.Parent.Event1 -- your text label here
local target = os.time() + 10800 (3 hours)
while true do
Event1.Text = "Event 1 ["..toHMS(target - os.time()).."]"
wait(1)
end
And this work and make it Event 1 [3:00:00] and countdown until 0 seconds
So this is already work to make as a countdown for one event, but how to make it for 3 events,
so it’s gonna be like
Event 1 [1:00:00]
Event 2 [2:00:00]
Event 3 [3:00:00]
And it countdown those 3 events, when event 1 reach 0, it moves to down and start with 3 hours, and event 2 gonna be on top, and result is
Event 2 [1:00:00]
Event 3 [2:00:00]
Event 1 [3:00:00]
And same process again for event 2, repeated.
I think this is the answer.
Keep in mind that this uses UTC and military time.
local events = {}
events.eventOne = {
hour = 10,--the hour in military time
min = 0,--the minute of the hour
sec = 0,--the second of the minute
eventFunction = function() --anything in here runs when the event is called
print("Did event 1")
end
}
events.eventTwo = {
hour = 13,
min = 30,
sec = 25,
eventFunction = function()
print("Did event 2")
end
}
while wait(3) do
for i,v in pairs(events) do
local t = os.date("!*t", os.time())
if v.hour == t.hour and v.min == t.min then
if t.sec < v.sec + 5 and t.sec > v.sec-5 then
v.eventFunction()
end
end
end
end
So this is just one part and has 3 text labels and it start countdown, when Event A becomes 0, it will move to the bottom and start with 3:00:00 (3 hours) and event B become the top , event C in the middle. Same happens to event B, after event B time becomes 0, move into bottom and event C start becoming the top, event A move to middle, event B is in the bottom starting with C. Repeat again the process for Event C. Keep looping like this, well I use UIGrid so it can easy by making :Destroy and Clone again. But idk how to make it so even if player quit, the time still continue.
Using clone and destroy to get the right event on the top works just fine, and even if the player leaves the code will still get the correct times. If you needed something else, please try to be clearer.
It is based on real time. It gets the real time (UTC) and checks if it’s time for the event to happen. That means that if you open multiple servers at the different times, the events will still happen at the same time.
Here is the script again, but this time I will try and explain better. This code is inside a server script, which is inside server script service. And by military i mean 24h time.
local events = {}
events.eventOne = {
hour = 10,--the hour in military time of when the event will happen
min = 0,--the minute of the hour
sec = 0,--the second of the minute
eventFunction = function()
--when it's time for the event, any code in here will run
print("Did event 1")
end
}
events.eventTwo = {
hour = 13,--the hour in military time of when the event will happen
min = 30,--the minute of the hour
sec = 25,
eventFunction = function()
--when it's time for the event, any code in here will run
print("Did event 2")
end
}
events.eventThree = {
hour = 16,--the hour in military time of when the event will happen
min = 45,--the minute of the hour
sec = 0,--the second of the minute
eventFunction = function()
--when it's time for the event, any code in here will run
print("Did event 3")
end
}
-- any code below this line should not be changed, it works just fine on it's own.
while wait(3) do
for i,v in pairs(events) do
local t = os.date("!*t", os.time())
if v.hour == t.hour and v.min == t.min then
if t.sec < v.sec + 5 and t.sec > v.sec-5 then
v.eventFunction()
end
end
end
end