Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

How would I make a timer GUI? [More info]

Asked by 9 years ago

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?

2 answers

Log in to vote
1
Answered by 9 years ago
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)
0
Thank you! nightmare13542 45 — 9y
0
Will this make it so each individual player has a different time? How would I make it so the time is the same for every player? nightmare13542 45 — 9y
0
It is for every individual player. I will change it for all players Tempestatem 884 — 9y
0
Thank you a ton! I've spent all day trying to get this right. nightmare13542 45 — 9y
View all comments (4 more)
0
I edited the script a bit trying to insert points where it would change the text, but now it's not working (The timer goes to 719, then stops) nightmare13542 45 — 9y
0
The edit is in the original question nightmare13542 45 — 9y
0
Oh! Woops I did something wrong let me edit it Tempestatem 884 — 9y
0
Nevermind, I don't see why this doesnt work. Here is the original script I got it from (From my game) I will edit my answer Tempestatem 884 — 9y
Ad
Log in to vote
1
Answered by
drahsid5 250 Moderation Voter
9 years ago

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()
0
Thank you so much for all the help guys! It's amazing to have such a great and caring community! nightmare13542 45 — 9y
0
If I wanted all players to die after the twelve minutes, where would I put that? nightmare13542 45 — 9y

Answer this question