I'm trying to create a GUI in which there's a twelve minute timer, and when the timer reaches zero, all players die, then it disables the GUI timer that kills people, puts another one up, that lasts for about 1 minute and thirty seconds, then after the one minute and thirty seconds, that timer disables, and it re-enables the one that lasts twelve minutes. I've tried so far, but all I have been able to do is mess a bunch of things up. Any tips on how I would make this happen? In a continuous never ending loop.
EDIT I edited the script you gave me, and now it stops at 719. Where did I go wrong?
time=time+720 for i=1, 720 do time=time-1 wait(1) for i, player in pairs(game.Players:GetPlayers()) do player.PlayerGui.TimerSet.Frame.Time.Text=tostring(time) -- Change it to wherever everything in the GUI is end player.PlayerGui.Timerset.Frame.PurgeInput.Text("Seconds until next Purge") end for i, player in pairs(game.Players:GetPlayers()) do player:BreakJoints() end time=time+90 for i=1, 90 do time=time-1 wait(1) for i, player in pairs(game.Players:GetPlayers()) do player.PlayerGui.TimerSet.Frame.Time.Text=tostring(time) -- Change it to wherever everything in the GUI is end end end player.PlayerGui.Timerset.Frame.PurgeInput.Text("Seconds until Purge ends")
EDIT Update: I got the script working in every way I wanted it to. One problem. How would I make it so that at the beginning of every timer, it would change the text in the other TextButton in the ScreenGui.Frame.PurgeInput.Text ||||||||| I cant do that without the whole things breaking... Where would I put it?
time=0 while true do wait() time=time+720 for i=1, 720 do time=time-1 wait(1) for i, player in pairs(game.Players:GetPlayers()) do player.PlayerGui.ScreenGui.Frame.TextLabel.Text=tostring(time) -- Change it to wherever everything in the GUI is end end for i, player in pairs(game.Players:GetPlayers()) do player:BreakJoints() end time=time+90 for i=1, 90 do time=time-1 wait(1) for i, player in pairs(game.Players:GetPlayers()) do player.PlayerGui.ScreenGui.Frame.TextLabel.Text=tostring(time) -- Change it to wherever everything in the GUI is end end end
Original Code
time=30 for i=1, 30 do time=time-1 wait(1) stat.TextLabel.Text=tostring(time)
This is easy. First, let's start by making a value for the time.
local Minutes = 12
Now your're likely asking "THAT'S 12, IF WE WAIT 12 THEN IT'LL WAIT IN SECONDS, RIGHT?" Well, yes. Just think though, We're scripting, we can use math. So, next we'll add;
_G.Seconds = Instance.new("IntValue") _G.Seconds.Value = (Minutes*60)
Yes, this is lazy, but if your minutes were something like '982936783623' then you'd not want to do that yourself, and it's more efficient. Next, we start the timer.
_G["Timer"] = function() end
Now, you might be asking "_G?? DERHAIL IS DAT?" So, I'll explain that too you. _G is something accessible by any script. So, that makes functions like the be able to be used by any script, which is a good thing, it can take lots of complexion out of some code. This also applies for the 'Seconds' value above; you can also make values accessible by any script with _G.
So now, we'll make a value for how many seconds that're left.
for index,child in pairs(_G:GetChildren()) do if child.Name == "Seconds Left" then print "Value already exsists." elseif child.Name ~= "Seconds Left" then _G["Seconds Left"] = Instance.new("Number Value") _G["Seconds Left"].Value = _G.Seconds.Value end end
Now, lets find our textbox
local TextBox = script.Parent.TextBox --Make this where your textbox is.
Next, we make a loop.
repeat until
Now, if the timer hits 0 we can do something;
until _G["Seconds Left"].Value <= 0 end TextBox.Text= "Match end" --Or whatever you want it too say
Now, we want our text box to always display the text.
TextBox.Text = (_G["Seconds Left"].Value/60).." Minutes left"
And now we subtract it, every loop,
_G["Seconds Left"].Value = (_G["Seconds Left"].Value-1)
Lets not forget to have the loop wait one second.
wait(1) --So easy.
Now, let's make it loop after some sort of wait
_G.Timer
So in the end it should look like this;
local Minutes = 12 --Add the number of minutes here. _G.Seconds = Instance.new("IntValue") _G.Seconds.Value = (Minutes*60) _G["Timer"] = function() for index,child in pairs(_G:GetChildren()) do if child.Name == "Seconds Left" then print "Value already exsists." elseif child.Name ~= "Seconds Left" then _G["Seconds Left"] = Instance.new("Number Value") _G["Seconds Left"].Value = _G.Seconds.Value end end local TextBox = script.Parent.TextBox repeat TextBox.Text = (_G["Seconds Left"].Value/60).." Minutes left" _G["Seconds Left"].Value = (_G["Seconds Left"].Value-1) wait(1) until _G["Seconds Left"].Value <= 0 end TextBox.Text= "Match end" --Or whatever you want it too say wait(60)--60 second intermission? _G.Timer()