Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
✓ ANSWER ACCEPTED

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

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!

1 comment

0

I know how to fix this, giving you an answer now!!!

2 answers

✓ Accepted answer

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

6 comments

0

its actually because hes comparing a object to a value

1

My way is good too.

1

also note that he could use an event 

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!

0

But I set a variable at the top, which waited for it.

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)

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

7 comments

0

I am checking if the value property is equal? Sauce Is A Bool Value

0

you need to first INDEX the property

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

0

What do you mean? In the script it says Sauce.Value? Sauce Is The BooleanValue and .Value is the property?

0

um look at your script

0

if script.Parent.Sauce == true then

0

a BooleanValue doesn't mean its directly a boolean, you need to first access the value its holding

This discussion is preserved as it was. New answers, comments, and votes are closed.