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

How would I make a timer that uses an IntValue? {Unsolved}

Asked by 10 years ago

Please read all of this before you answer

So far, no exaggeration, I have spent five days of trial and error, without any luck/ progression. I'm trying to make a timer script, Like the one seen in Ozzypigs 'Hunger Games', Please note: I'm not trying to copy his game, just using it as a reference, but so far, here are the problems I have run in to. -- Script not functioning at all- -- Script not registering the IntValue in Workspace- -- Timer resetting when player joins or dies- -- Script getting stuck at certain values- -- Studio crashing/freezing while trying to use scripts-

== As you might be able to see, I have gotten NOWHERE. I am not asking for a script, I know this isn't a request website, but I am asking for help. I am stuck, with nothing left, and I plan to release the game on the 15th, but at this rate, it probably won't happen. For those who answer, Thank you. For those who don't, Thanks anyways.

Info: -[]-The location of the timer is: game.Workspace.StarterGui.TimerSet.Frame.Time.Script -[]- I am trying to create a GUI!!!! - timer that is the SAME FOR EVERYONE, no matter if they reset, or a new player joins, No others reason. Just a timer that runs for 30 seconds, then twelve minutes, then after twelve minutes, kills everyone, then loops. -[]- I need the timer to be on a string so players can see the time left. Thank you. Any further questions, PLEASE comment them. Thanks again!

2 answers

Log in to vote
2
Answered by
HexC3D 830 Moderation Voter
10 years ago

Well you don't exactly need a IntValue to make a timer script. game.Workspace.StarterGui.TimerSet.Frame.Time.Script StarterGui is not a child of workspace, it is the child of the game and will be defined like this game.StarterGui.TimerSet.Frame.Time.Script In this case i'll show you an example how I would do it

Let's say there is an order in StarterGui

ScreenGui

Frame

TextLabel

for i,v in pairs(game.Players:GetPlayers()) do
Time = 30 -- 30 seconds
for i = Time,0,-1 -- It minus 30 by 1(look at wait) , that zero in the middle is that it stop at 0.
Time = i
v:WaitForDataReady("StarterGui").ScreenGui.Frame.TextLabel.Text = ""..Time -- Get's all the players TextLabel And changes the time!!
wait(1) -- For every 1 second it subtracts 1 from Time which is equal to 30.
end
end

If this helped +1

0
A value would be better in my opinion. Tesouro 407 — 10y
0
But it still works.. HexC3D 830 — 10y
0
Yeah. Tesouro 407 — 10y
0
I'm still confused as to what I am to do, but I suppose I'll +1 nightmare13542 45 — 10y
0
I made sure it's not confusing anymore HexC3D 830 — 10y
Ad
Log in to vote
1
Answered by
Tesouro 407 Moderation Voter
10 years ago

Ok, there you have your script inside the Gui and an IntValue in your Workspace, called Timer. The Gui has a text label and the time will be set in seconds.

timer = game.Workspace.Timer
text = script.Parent.TextLabel -- or wherever it is
timer.Changed:connect(function() -- runs everytime the value changes
    if timer.Value < 60 and timer.Value > 0 then -- if it's less than 1 minute
        text.Text = tostring(timer.Value) .. " second(s) left" -- turns the value into text
    elseif timer.Value >= 60 and timer.Value > 0 then -- if it's more than one minute
        seconds = timer.Value % 60 -- subtracts the minutes and leave the seconds
        minutes = math.floor(timer.Value / 60) -- takes the minutes
        text.Text = tostring(minutes) .. " minute(s) and " .. tostring(seconds) .. " second(s) left" -- bring both to text
    else -- when it's over
        text.Text = "Game Over!"
        -- run some function to end the game
    end
end)

Inside the value this simple script:

script.Parent.Value = 120 -- the total time players have, in seconds
while true do --  a loop
    wait(1) -- wait 1 second
    script.Parent.Value = script.Parent.Value - 1 -- takes one second from the value
end

To start counting the time, just enable the script and you're done.

If you need more help: http://wiki.roblox.com/index.php?title=Math http://wiki.roblox.com/index.php?title=String_manipulation http://wiki.roblox.com/index.php?title=String

[Edit]

script.Parent.Value = 30 -- the first 30 seconds
while true do --  a loop
    wait(1) -- wait 1 second
    script.Parent.Value = script.Parent.Value - 1
end
script.Parent.Value = 720 -- the final 12 minutes
while true do --  a loop
    wait(1) -- wait 1 second
    script.Parent.Value = script.Parent.Value - 1
end
0
It may look difficult, but just put it into studio editor and you will understand. Tesouro 407 — 10y
0
Ah.. Nothing happens. The timer stays at '000' its normal text... nightmare13542 45 — 10y
0
ahn, did you place each script where it's supposed to? Tesouro 407 — 10y
0
and did you change the 2nd line to fit your text gui? Tesouro 407 — 10y
View all comments (8 more)
0
Yes, I edited something, and now it's working, but two more questions, so the timer runs, its 1 Minute and 60 seconds(2 mins) How would I make it so it runs for 30 seconds, then runs for 12 minutes, and at the end of 12 minutes, it kills everyone? nightmare13542 45 — 10y
0
Huh, just edit the value script, make it 30, loop it down, then make it 120 and loop it again. Tesouro 407 — 10y
0
It keeps crashing studio.. Any idea why? Never happened before. ;-; nightmare13542 45 — 10y
0
Also, I have no idea how to do that. v_v Sorry. """Huh, just edit the value script, make it 30, loop it down, then make it 120 and loop it again."""" nightmare13542 45 — 10y
0
Maybe you didn't put a wait. I will edit my answer Tesouro 407 — 10y
0
Thank you. nightmare13542 45 — 10y
0
How would I make it so it kills all players, but only after the twelve minute period, not the thirty second one? nightmare13542 45 — 10y
0
Also, the script/timer runs for thirty seconds, then gets stuck at the "Game Over!" message... nightmare13542 45 — 10y

Answer this question