I was making a script to check if a value is true using a while wait() do loop. I went to test (I was testing it on the server side) And I changed the Sauce value to true but nothing was printing? (Sauce Is A Bool Value) Can someone please explain why this is happening?
while wait() do -------------------------------------------------------------- I Tried Placing a print in this position and it DID work! if script.Parent.Sauce == true then print("test") script.Parent.SurfaceGui.Sauce.Visible = true print("test2") end end
I tested placing a print("test") right after the while wait() do and that was working fine but I think the problem has something to do with the game not detecting if Sauce == true? Please help!
So I had this problem before to. You have to let the variable load before you actually use it. Here is your fixed script, which should work much better!
local sauce = script.Parent:WaitForChild("Sauce") while wait() do if sauce.Value == true then print("test") script.Parent.SurfaceGui.Sauce.Visible = true print("test2") end end
its because your comparing an instance to a value, instead just check if the Value
property is equal to true. also use :GetPropertyChangedSignal()
instead of a while loop to reduce latency.
script.Parent.Sauce:GetPropertyChangedSignal("Value"):Connect(function() -- listen when the Value property changed if script.Parent.Sauce.Value == true then print("test") script.Parent.SurfaceGui.Sauce.Visible = true print("test2") end end)