This showed up with no errors in the output
game_ended = script.Parent.gameEnded game_time = script.Parent.gameTime game_time_test = script.Parent.gameTime_Test --times = game_time.Value 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) --wait(game_time.Value) game_ended.Value = true script.Disabled = true
This is supposed to countdown by game_time_test
's Value (10), and disable after it's done. Any help please?
I've reformatted the script a bit to understand it better. It should still work precisely like yours.
--game_time = script.Parent.gameTime --times = game_time.Value game_ended = script.Parent.gameEnded game_time_test = script.Parent.gameTime_Test times = game_time_test.Value --10 timesnum = times --Also 10 while game_ended.Value == false do if times <= 0 then times = timesnum --Reset times to 10 else script.Parent.Text = "Time Left : "..times wait(1) times = times - 1 end end wait(game_time_test.Value) --Wait 10 seconds --wait(game_time.Value) game_ended.Value = true --Try to turn off the loop 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_time = script.Parent.gameTime --times = game_time.Value game_ended = script.Parent.gameEnded game_time_test = script.Parent.gameTime_Test times = game_time_test.Value --10 timesnum = times --Also 10 spawn(function() --Spawning a thread so it runs in the background. while game_ended.Value == false do if times <= 0 then times = timesnum --Reset times to 10 else script.Parent.Text = "Time Left : "..times wait(1) times = times - 1 end end end) wait(game_time_test.Value) --Wait 10 seconds --wait(game_time.Value) game_ended.Value = true script.Disabled = true