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

why its dont work?

Asked by 8 years ago

Please make your question title relevant to your question content. It should be a one-sentence summary in question form.

Hello everyone, i need a help. I have a script:

while GameStart == true do
    TimerMessage = Instance.new("Hint", game.Workspace)
    TimerMessage.Text = "This game will end in " ..TimerValue.. " seconds"
    wait(1)
    TimerValue = TimerValue - 1
    TimerMessage:remove()
end

if TimerValue == 0 then
    GameStart = false
    IsArtist = false
    TimerValue = 120
end

and when value TimerValue = 0 loop doesnt stop. halp. Sorry for my bad english i am not from english countries.

1 answer

Log in to vote
1
Answered by 8 years ago
while GameStart == true do
    TimerMessage = Instance.new("Hint", game.Workspace)
    TimerMessage.Text = "This game will end in " ..TimerValue.. " seconds"
    wait(1)
    TimerValue = TimerValue - 1
    TimerMessage:remove()
    if TimerValue == 0 then
        GameStart = false
        IsArtist = false
        TimerValue = 120
    end
end

The problem you were having is you had it underneath the While loop. Loops will continuously run, until told to stop, and the thing stopping your loop was GameStart, and the only time it was changed is underneath the loop.

I put that part of code at the bottom of the loop, so every time it loops it checks to see if TimerValue is == 0, and if it is then it will change GameStart to false, thus stopping the loop, and continuing down the script.

I would suggest for this kind of script to use a For loop, as it would be simpler to countdown, for example something like:

for i = 10, 0, -1 do
    print(i)
end

Would print: 10, 9 , 8, 7, 6, 5, 4, 3, 2, 1, 0, in the Output and it is a lot more effective.

For more on For loops or just any loop in general, check out the Wiki.

If the script still doesn't work, please Edit your question with the script, and any errors in the output.

If it does work, then please be sure to +1 and accept the answer.

  • NinjoOnline
0
Thanks NinjoOnline, its works VladFox 5 — 8y
0
No problem :) NinjoOnline 1146 — 8y
Ad

Answer this question