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?
1 | while wait() do |
2 | -------------------------------------------------------------- I Tried Placing a print in this position and it DID work! |
3 | if script.Parent.Sauce = = true then |
4 | print ( "test" ) |
5 | script.Parent.SurfaceGui.Sauce.Visible = true |
6 | print ( "test2" ) |
7 | end |
8 | 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!
1 | local sauce = script.Parent:WaitForChild( "Sauce" ) |
2 | while wait() do |
3 |
4 | if sauce.Value = = true then |
5 | print ( "test" ) |
6 | script.Parent.SurfaceGui.Sauce.Visible = true |
7 | print ( "test2" ) |
8 | end |
9 | 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.
1 | script.Parent.Sauce:GetPropertyChangedSignal( "Value" ):Connect( function () -- listen when the Value property changed |
2 | if script.Parent.Sauce.Value = = true then |
3 | print ( "test" ) |
4 | script.Parent.SurfaceGui.Sauce.Visible = true |
5 | print ( "test2" ) |
6 | end |
7 | end ) |