✓ Accepted answer
I've reformatted the script a bit to understand it better. It should still work precisely like yours.
game_ended = script.Parent.gameEnded
game_time_test = script.Parent.gameTime_Test
times = game_time_test.Value
timesnum = times
while game_ended.Value == false do
if times <= 0 then
times = timesnum
else
script.Parent.Text = "Time Left : "..times
wait(1)
times = times - 1
end
end
wait(game_time_test.Value)
game_ended.Value = true
script.Disabled = true
The problem here is that loops will not let you continue on in the script until they're done. So, you can't turn the loop off like that. To fix this, we have the built-in spawn function to let loops run in the background. Example:
spawn(function()
while wait(1) do
print("hey")
end
end)
spawn(function()
while wait(.8) do
print("hi")
end
end)
while wait(.7) do
print("what's up")
end
To apply this to your script:
game_ended = script.Parent.gameEnded
game_time_test = script.Parent.gameTime_Test
times = game_time_test.Value
timesnum = times
spawn(function()
while game_ended.Value == false do
if times <= 0 then
times = timesnum
else
script.Parent.Text = "Time Left : "..times
wait(1)
times = times - 1
end
end
end)
wait(game_time_test.Value)
game_ended.Value = true
script.Disabled = true
1 comment
What does it do instead?