Does anyone here know how to make like Countdown for events(not only 1 event), so the events repeated every 3 hours, there are 3 events, So in the surface gui there will be 3 events countdown, so after the first event finish, it will be on the below again repeating, the second one gonna be on the top,
So like 3 events , event a, b and c
It will start the countdown like
Event A [1:00:00]
Event B [2:00:00]
Event C [3:00:00]
It will countdown for until Event A become 0:00:00 and the text also change for minutes and seconds and become
Event B [1:00:00]
Event C [2:00:00]
Event A [3:00:00]
And last, the same process , until event B becomes 0:00:00 , moves to event C as the top and event A becoming the second
Event C [1:00:00]
Event A [2:00:00]
Event B [3:00:00]
And repeating again from the first time
Format : Event Name [hours:minutes:seconds]
With surface gui on a part
Well Usually I see Live Events but using like when the date to that event , but I want Live Events repeating every 3 hours
Okay I get exactly what you want and I just made it too! Do know it’s really not “lag/latency” free. So let me step by step walk you through so you understand and the full code sample will be the last step.
I understand what you mean here but no player in a server = game:BindToClose() meaning the server gets shutdown. But don’t worry it will countdown always if there is a player in the server.
Ahh what I mean is like this, Event 1 is every 10 am , 13 am , 16 am, same to event 2 is every 11 am, 14 am, 17 am, same to event 3 12 am, 15 am, 18 am, so it’s 3 hours right? Based on time, everyday. But i think start with every 3 hours without depending on time is good enough for beginning.
You’ll need to know all the the below to fully understand
os.clock()
os.time()
os.date()
loops
functions
delays/waits a.k.a ( wait(1) or task.wait(1) )
Firstly add a server script/local script into your game
Secondly Add a ScreenGui and two Text Labels (to show how this works I’ll just be showing the time going up but it can be edited to do anything)
Third The Code Sample
Code and Explanation
This is the server script version
UI = nil -- the screengui
Val = nil -- textlabel
Num = nil -- textlabel
game.Players.PlayerAdded:Connect(function(plr) -- so we connect to the player
UI = plr.PlayerGui:WaitForChild("EE") -- we set the blank variables
Val = UI.val -- variable set
Num = UI.num -- variable set
end)
task.wait(5) -- delay for the player
warn("running") -- just some prints can be removed
warn("-----------") -- <-- subject to be removed
local a = 5 -- these are in seconds so
local b = 10 -- you can change them to hours like this
local c = 15 -- e.g. [ local d = 60 * 60; local e = (60 * 60) * 2 ]
-- as you can see d is equal to a hour and e is equal to 2
-- a,b,c are our **MAIN** variables besides os()
Onto part two now where functions come into play
function hour(timestamp:number)
return os.date("%I", timestamp)
end
function minute(timestamp:number)
return os.date("%M", timestamp)
end
function sec(timestamp:number)
return os.date("%S", timestamp)
end
-- by the name you can tell what they do
-- yeah these function return the hour, minute, and sec for you
Okay now these functions contains loops so a little bit tricky but familiar
function A()
local stop = os.time() + a
local num = 0
repeat
num += 1
Val.Text = hour(os.time()).. ":"..minute(os.time())..":"..sec(os.time())
Num.Text = "A: ".. num
task.wait(1)
until
stop <= os.time()
print("finished a")
end
function B()
local stop = os.time() + b
local num = 0
repeat
num +=1
Val.Text = hour(os.time()).. ":"..minute(os.time())..":"..sec(os.time())
Num.Text = "B: ".. num
task.wait(1)
until
stop <= os.time()
print("finished b")
end
function C()
local stop = os.time() + c
local num = 0
repeat
num += 1
Val.Text = hour(os.time()).. ":"..minute(os.time())..":"..sec(os.time())
Num.Text = "C: ".. num
task.wait(1)
until
stop <= os.time()
print("finished c")
end
-- I'll summarize right down here in the best way posible
-- the "stop" variable is when the loop will stop
-- the "num" variable just tells you how far in the loop you are
-- lastly the function fire a repeating matter of adding a number and
-- setting a textlabel to the date "found at Val.Text = "
-- and also waits 1 sec as to real life and then stops
-- after the until when the os.time() is more than the stop variable
Last piece of code information! and the easiest
while task.wait() do
A()
B()
C()
end
-- why no waits? well to tell you like this it doesn't need any. Why?
-- Well because when you fire A() or B() or C() it yeilds(stops) then current loop
-- to start the loop inside of the function and when the "repeat until" loop is finished
-- it starts back the "while wait loop" and fires the other function.
Full Code
-- Server Code should be inside serverscriptservice
UI = nil
Val = nil
Num = nil
game.Players.PlayerAdded:Connect(function(plr)
UI = plr.PlayerGui:WaitForChild("EE")
Val = UI.val
Num = UI.num
end)
task.wait(5)
warn("running")
warn("-----------")
local a = 5
local b = 10
local c = 15
function hour(timestamp:number)
return os.date("%I", timestamp)
end
function minute(timestamp:number)
return os.date("%M", timestamp)
end
function sec(timestamp:number)
return os.date("%S", timestamp)
end
function A()
local stop = os.time() + a
local num = 0
repeat
num += 1
Val.Text = hour(os.time()).. ":"..minute(os.time())..":"..sec(os.time())
Num.Text = "A: ".. num
task.wait(1)
until
stop <= os.time()
print("finished a")
end
function B()
local stop = os.time() + b
local num = 0
repeat
num +=1
Val.Text = hour(os.time()).. ":"..minute(os.time())..":"..sec(os.time())
Num.Text = "B: ".. num
task.wait(1)
until
stop <= os.time()
print("finished b")
end
function C()
local stop = os.time() + c
local num = 0
repeat
num += 1
Val.Text = hour(os.time()).. ":"..minute(os.time())..":"..sec(os.time())
Num.Text = "C: ".. num
task.wait(1)
until
stop <= os.time()
print("finished c")
end
while task.wait() do
A()
B()
C()
end
-- Client code can be put inside the ScreenGui inside a localscript
Plr = game.Players.LocalPlayer
UI = Plr.PlayerGui:WaitForChild("EE")
Val = UI.val
Num = UI.num
task.wait(5)
warn("running")
warn("-----------")
local a = 5
local b = 10
local c = 15
function hour(timestamp:number)
return os.date("%I", timestamp)
end
function minute(timestamp:number)
return os.date("%M", timestamp)
end
function sec(timestamp:number)
return os.date("%S", timestamp)
end
function A()
local stop = os.time() + a
local num = 0
repeat
num += 1
Val.Text = hour(os.time()).. ":"..minute(os.time())..":"..sec(os.time())
Num.Text = "A: ".. num
task.wait(1)
until
stop <= os.time()
print("finished a")
end
function B()
local stop = os.time() + b
local num = 0
repeat
num +=1
Val.Text = hour(os.time()).. ":"..minute(os.time())..":"..sec(os.time())
Num.Text = "B: ".. num
task.wait(1)
until
stop <= os.time()
print("finished b")
end
function C()
local stop = os.time() + c
local num = 0
repeat
num += 1
Val.Text = hour(os.time()).. ":"..minute(os.time())..":"..sec(os.time())
Num.Text = "C: ".. num
task.wait(1)
until
stop <= os.time()
print("finished c")
end
while task.wait() do
A()
B()
C()
end
local h = 0
local m = 0
local s = 0
local formula
local Time = 5 -- seconds
function CountDown(number)
h = 0
m = 0
s = 0
for i=1, number do
s = s + 1
if s == 60 then s = 0
m = m + 1
end
if m == 60 then m = 0
h = h + 1
end
end
end
function Looperfunction(Time:number, any:"function")
local stop = os.time() + Time
local num = 0
local formula
--Before the loop
repeat
CountDown(Time)
Time -= 1
formula = h.. ":".. m.. ":".. s
workspace.TimePlace.SurfaceGui.GlobalTime.Text = formula
if any then any(workspace.TimePlace) end -- if you don't want the function to play
-- within the loop then move it to before
task.wait(1)
until
stop <= os.time()
--After the loop
--print("finished a")
end
function LooperfunctionB(Time:number, any:"function")
local stop = os.time() + Time
local num = 0
local formula
--Before the loop
if any then any(workspace.TimePlace) end
repeat
CountDown(Time)
Time -= 1
formula = h.. ":".. m.. ":".. s
workspace.TimePlace.SurfaceGui.GlobalTime.Text = formula
-- if you don't want the function to play
-- within the loop then move it to before
task.wait(1)
until
stop <= os.time()
--After the loop
--print("finished a")
end
while true do
Looperfunction(5, function() print("hello") end)
LooperfunctionB(10, function() print("bye") end)
Looperfunction(15)
end
I sent a wrong script before this it what you want. I got confused and added some customizable things just tell me if you have any questions.
But what I want is with 3 text label? so 3 text label Event A, B and C
So the surface gui has 3 text labels with UI list or UI grid
so when its start
The top is Event A
Middle is Event B
Bottom is Event C
and countdown until A = 0
Event B becomes the top, Event C becomes in the middle
Event A becomes the bottom
Repeat same process for Event B, Like the picture below, so when Event A finish or time = 0, Event A move into below and start again with 3:00:00 (3 hours) and Event B becomes on the top
Well what I want is like this so countdown all events, when event A finish, event B becomes on the top, and event A start again from bottom with 3 hours and repeating
Basically you’d just have to update the looper function to do a sole function at the end of it because when it ends you want it to change the event right?
local h = 0
local m = 0
local s = 0
local formula
local topBuildBoard = The Top text label
local MiddleBuildBoard = The Middle text label
local BottomBuildBoard = The Bottom text label
local Time = 5 -- seconds
local debounce = 1
function CountDown(number) -- gives us the number converted into time
h = 0
m = 0
s = 0
for i=1, number do
s = s + 1
if s == 60 then s = 0
m = m + 1
end
if m == 60 then m = 0
h = h + 1
end
end
end
function LooperfunctionA(Time:number, any:"function", text:string) -- fires a function after the loop
local stop = os.time() + Time
local num = 0
local formula
--Before the loop
repeat
CountDown(Time)
Time -= 1
formula = h.. ":".. m.. ":".. s
topBuildBoard.Text = "Event "..text.." [".. formula.. "]"
-- if you don't want the function to play
-- within the loop then move it to before
task.wait(1)
until
stop <= os.time()
debounce += 1
if any then any(debounce) end
--After the loop
--print("finished a")
end
function Refresh(check)
if check == 1 then
--topBuildBoard.Text = "Event A "
MiddleBuildBoard.Text = "Event B "
BottomBuildBoard.Text = "Event C "
end
if check == 2 then
--topBuildBoard.Text = "Event B "
MiddleBuildBoard.Text = "Event C "
BottomBuildBoard.Text = "Event A "
end
if check == 3 then
--topBuildBoard.Text = "Event C "
MiddleBuildBoard.Text = "Event A "
BottomBuildBoard.Text = "Event B "
debounce = 0 -- resets it back to the beginning
end
end
while true do
LooperfunctionA(5, Refresh, "A") -- event A
LooperfunctionA(10, Refresh, "B") -- Event B
LooperfunctionA(15, Refresh, "C") -- Event C
end
--Output will most likely look like :
-- Event A [0:0:5]
-- Event B
-- Event C
Well ur script work but I want it like this, i give example,
On the text label it will start with
– this is example (1 Hour)
Event A [1:00:00]
Event B [2:00:00]
Event C [3:00:00]
Then All 3 labels countdown, after A becomes 0 and B becomes 1:00:00, but all this 3 labels do countdown
It will change into
Event B [1:00:00]
Event C [2:00:00]
Event A [3:00:00]
And repeat same process