Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
1

(Answered) Script Doesn't Detect If Variable Is True?

Asked by 5 years ago
Edited 5 years ago

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!

0
I know how to fix this, giving you an answer now!!! CaptainD_veloper 290 — 5y

2 answers

Log in to vote
0
Answered by 5 years ago

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
0
its actually because hes comparing a object to a value User#23365 30 — 5y
1
My way is good too. CaptainD_veloper 290 — 5y
1
also note that he could use an event  User#23365 30 — 5y
0
Your Script Had 1 Small Mistake which was you did sauce.Value instead of script.Parent.Sauce.Value But When I changed that it worked :) Thank You! kizi3000 88 — 5y
View all comments (2 more)
0
But I set a variable at the top, which waited for it. CaptainD_veloper 290 — 5y
0
yea Ik thats what I did wrong, Thank You For Helping :) (I Cant up vote your answer yet because I only have 22 reputation) kizi3000 88 — 5y
Ad
Log in to vote
1
Answered by 5 years ago
Edited 5 years ago

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)

:GetPropertyChangedSignal()

latency

0
I am checking if the value property is equal? Sauce Is A Bool Value kizi3000 88 — 5y
0
you need to first INDEX the property User#23365 30 — 5y
0
ur just comparing a boolean value to a instance (object) not another boolean, in which the object will never be true nor a boolean value User#23365 30 — 5y
0
What do you mean? In the script it says Sauce.Value? Sauce Is The BooleanValue and .Value is the property? kizi3000 88 — 5y
View all comments (3 more)
0
um look at your script User#23365 30 — 5y
0
if script.Parent.Sauce == true then User#23365 30 — 5y
0
a BooleanValue doesn't mean its directly a boolean, you need to first access the value its holding User#23365 30 — 5y

Answer this question