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

How would I make a script do a function under the condition that a value is true and/or false?

Asked by
Stycon 30
5 years ago

I want to have a script find the value of a "Value" object. I tried if script.Parent.Parent.myvalue.Value = false then (My door function) The script thinks that the "=" is supposed to be "then". Is there a way to make the code find the value of "myvalue" and make the door open under the condition that "myvalue" is a certain value?

1 answer

Log in to vote
1
Answered by 5 years ago
Edited 5 years ago

The script threw that error, because the = operator is exclusively for assignments. When you want to use comparisons, you use the == operator, which checks equality. Your script should look like this:

if script.Parent.Parent.myvalue.Value == false then
    --...
end

But that can be made more efficient! It's true!

if not script.Parent.Parent.myvalue.Value then
    --...
end

Seeing you are new to the site, the most helpful answers to questions are to be accepted by clicking the 'Accept Answer' button. I'm not asking for you to accept my answer, if a better answer comes out, go ahead and accept that one instead.

0
Thanks! That really helps! Stycon 30 — 5y
Ad

Answer this question