Live Countdownt (More than one event)

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.

Please help me, thank you

2 Likes

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
1 Like

How to make it to Surface GUI text labels? I have three events so three text labels

1 Like

I’m not quite sure I understand what you are saying. Do you want events that change text labels?

1 Like

I will send pics maybe u will understand



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.

1 Like

I use :Destroy and :Clone again because that’s the only idea i can get, but if u have better is good.

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.

Hey, I wanna ask can we make it based on real time, so with real time even if there is no player in the server, it still continue, because real time.

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.

Is that a module? How to use it to the script then.

Because in my script I dont use module. and Military time, do u mean 24h?

1 Like

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
1 Like

So i supposed I should do the Destroy and Clone in this part?

eventFunction = function()
	--when it's time for the event, any code in here will run
	print("Did event 1")
end
1 Like

yes, that is what you’re supposed to do. I have to go now, but if I solved your problem please mark my post as the solution.

1 Like

And how to connect it to the text label tho? Which one should I edit.

1 Like

Edit:
Didn’t realize yielding wasn’t your problem.

If you send a picture of your hierarchy (use explorer window) I can show you how to reference instances in it.

Basically use the Parent property of Instances to go up then select specific children (ex: Parent.TextLabel) to go down.

Well I already do but what I want is based on real time sooo on the other server is the same.

1 Like

for event 1 edit label 1, for event 2 edit label 2, and for event 3 edit label 3.

in the eventFunction ? yes? or no

1 Like

yes, in the eventFunction. I can’t answer any more questions for now, if you don’t have the solution yet then I will get back to you tommorrow.