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?
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