Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
COMMUNITY QUESTION

How do I make a countdown gui that automatically resets everything at a certain time?

For example, if there is a battle going on, I want a countdown gui that counts from two minutes to zero seconds. When it gets to zero, I want everyone to automatically change team then die. Next, I want another countdown gui that goes from 30 sec to 0 sec. When it reaches 0 sec, I want it to change team and die again. Then I want it to repeat on and on. So far I got this:

local seconds = 120 -- 120 seconds, meaning 2 minutes.
local timer = script.Parent -- Timer object!
seconds = ((seconds > 1 and seconds) or 1)

function startTimer()
local begin = tick()
while tick() < begin + seconds do
local diff = (math.floor(tick()) - (begin + seconds))
timer.Text = math.floor(seconds / 60) .. ":" .. (seconds % 60)
wait(0.1)
end
for k,v in pairs(game:service("Players"):GetPlayers()) do
if v.Character and v.Character:FindFirstChild("Humanoid") then
v.Character:FindFirstChild("Humanoid").Health = 0
end
end

startTimer()

I tried it, but it seems like it's not working. How can I improve this?

2 comments

0

????????????? what r u doing

0

confusion

2 answers

I didn't really understand you so I just did as much as I can.

script.Parent.Value = 30 -- Change this to how many seconds the timer is.

-- If Its Battling Time then
for i = 1,10 do
	wait(1)
	script.Parent.Value = script.Parent.Value - 1
end

-- it will check if the value is 0.
script.Parent.Value.Changed:Connect(function()
	if script.Parent.Value == 0 then
	-- do stuff

end)
	


local seconds = 120 -- 120 seconds, meaning 2 minutes.
local seconds2 = 30 -- Idk whats his for, but you wnated it
local timer = script.Parent -- Timer object!
seconds = ((seconds > 1 and seconds) or 1)

function startTimer()
local begin = tick()
while tick() < begin + seconds do
local diff = (math.floor(tick()) - (begin + seconds))
timer.Text = math.floor(seconds / 60) .. ":" .. (seconds % 60)
wait(0.1)
end
for k,v in pairs(game:service("Players"):GetPlayers()) do
if v.Character and v.Character:FindFirstChild("Humanoid") then
v.Character:FindFirstChild("Humanoid").Health = 0
end
end

function startTimer2()
local begin = tick()
while tick() < begin + seconds do
local diff = (math.floor(tick()) - (begin + seconds))
timer.Text = math.floor(seconds2 / 60) .. ":" .. (seconds2 % 60)
wait(0.1)
end
for k,v in pairs(game:service("Players"):GetPlayers()) do
if v.Character and v.Character:FindFirstChild("Humanoid") then
v.Character:FindFirstChild("Humanoid").Health = 0
end
end

while true do
startTimer()
startTimer2()
end

This discussion is preserved as it was. New answers, comments, and votes are closed.