Hi, I asked a related question the other day and it got answered, so thanks to YellowTide.
My problem now is that the timer will not start when all the bool values are true.
timer=1 totaltimer=1 ValueA = game.Workspace.PartA.ValueA ValueB = game.Workspace.PartB.ValueB ValueC = game.Workspace.PartC.ValueC if ValueA.Value == true and ValueB.Value == true and ValueC.Value == true then repeat print'cool' wait(1) timer = timer + 1 until timer > 3 if timer > 3 then timer=totaltimer end game.Lighting.RaidersWin:Clone().Parent = game.Players.LocalPlayer.PlayerGui for i, player in ipairs(game.Players:GetPlayers()) do if player.Character then local hum = player.Character:FindFirstChild('Humanoid') if hum then hum.Health = 0 timer=totaltimer ValueA.Value=false ValueB.Value=false ValueC.Value=false game.Workspace.PartA.BrickColor.new=BrickColor.new"Earth green" game.Workspace.PartB.BrickColor.new=BrickColor.new"Earth green" game.Workspace.PartC.BrickColor.new=BrickColor.new"Earth green" end end end end
What this code should do is start a timer that counts to 3 when all the values are true, then after 3 seconds it clones a Gui into everyone's PlayerGui, then resets the timer and kills everyone. The timer would end if a value becomes false and reset to 0.
For some reason the above will not work. Thanks for reading!
You're using an if statement
, expecting it to act like a listener. if statements will activate at the time the script reads the statement.. it will pass if the condition is true, otherwise will not.
You need to have a loop
check repeatedly until all the conditions are met - e.g. all the variables being true.
for this case, you can use a repeat loop
local timer = 1 local totaltimer = 1 local ValueA = game.Workspace.PartA.ValueA local ValueB = game.Workspace.PartB.ValueB local ValueC = game.Workspace.PartC.ValueC repeat wait() until ValueA.Value and ValueB.Value and ValueC.Value repeat print'cool' wait(1) timer = timer + 1 until timer > 3 timer = totaltimer game.Lighting.RaidersWin:Clone().Parent = game.Players.LocalPlayer.PlayerGui for i, player in ipairs(game.Players:GetPlayers()) do if player.Character then local hum = player.Character:FindFirstChild('Humanoid') if hum then hum.Health = 0 timer=totaltimer ValueA.Value=false ValueB.Value=false ValueC.Value=false workspace.PartA.BrickColor = BrickColor.new('Earth green') workspace.PartB.BrickColor = BrickColor.new('Earth green') workspace.PartC.BrickColor = BrickColor.new('Earth green') end end end
using an if then only checks once.
try using;
repeat wait() until ValueA.Value == true and ValueB.Value == true and ValueC.Value == true
this will keep wait()ing until all value's = true. Put this on line 6 and it will wait and start the timer when all are true.
repeat (what you want to happen) until (condition) this is a loop that works well for waiting for something to happen.
Hope this helps. :)