I was attempting to activate and deactivate values to run all the scripts in my game but the loop does'nt seem to run, i was looking to see who could help and solve my issue :D THANKS FOR READING
while true do local Gamestart = workspace.Gamestart.Value local Intermission = workspace.Intermission.Value local Inttime = workspace.Inttime.Value local Resources = workspace.Resources.Value wait(30) Intermission = true Inttime = Inttime -1 if Inttime == 0 then Intermission = false Inttime = 30 wait() Gamestart = true if Resources == 0 then Gamestart = false local plrs = game.Players:GetPlayers() for _, player in pairs(plrs) do if player.Character and player.Character:FindFirstChild("Humanoid") then player.Character.Humanoid.Health = 0 end end end end end
You basically had a bunch of the same error in your script. I'll go ahead, and post the fixed script first, then explain it a bit.
Here it is:
while true do local Gamestart = workspace.Gamestart local Intermission = workspace.Intermission local Inttime = workspace.Inttime local Resources = workspace.Resources Intermission.Value = true repeat wait(1) --Repeats following code every second if Inttime.Value>0 then Inttime.Value=Inttime.Value-1 end until Inttime.Value<=0 --Stop repeating once it hits 0 if Inttime.Value == 0 then Intermission.Value = false Inttime.Value = 30 wait() Gamestart.Value = true if Resources.Value == 0 then Gamestart.Value = false local plrs = game.Players:GetPlayers() for _, player in pairs(plrs) do if player.Character and player.Character:FindFirstChild("Humanoid") then player.Character.Humanoid.Health = 0 end end end end end
So basically, the error you had was that you were defining the Variables: Gamestart, Intermission, Inttime, and Resources, as their Values. When you do this, the script stores the variable as what the value of it was at the time it was called.
Here's an example:
local ValueExample=script.Parent.Value --Let's say this comes out as true script.Parent.Value=not script.Parent.Value --Changes the value to false print(ValueExample) --Would print out "true"
This would happen because the value is being changed correctly, but as I already stated, it is storing the value, not the object that you need to access to change it's property.
To fix the above script, we would do this:
local ValueExample=script.Parent --Let's say this is true again script.Parent.Value=not script.Parent.Value --Changes the value to false print(ValueExample.Value) --Would print out "false" this time
This time we accessed the object, and were able to change it's property correctly, so the script worked out how we wanted it to.
Anyways, I hope this helped you out a bit. If you have any problems/questions, please leave a comment below :P
To make it count down you need to make it wait 1 second, and then subtract 1 from the timer value
while true do local Gamestart = workspace.Gamestart local Intermission = workspace.Intermission local Inttime = workspace.Inttime local Resources = workspace.Resources Intermission.Value = true wait() while Inttime.Value ~= 0 do -- this will keep counting down till the inttime has reached zero wait(1) -- waiting 1 second Inttime.Value = Inttime.Value -1 -- subtracting 1 each second end if Inttime.Value == 0 then Intermission.Value = false Inttime.Value = 30 wait() Gamestart.Value = true if Resources.Value == 0 then Gamestart.Value = false local plrs = game.Players:GetPlayers() for _, player in pairs(plrs) do if player.Character and player.Character:FindFirstChild("Humanoid") then player.Character.Humanoid.Health = 0 end end end end end
This should countdown now :D Hope this helped!