# Multiple or's in an if statement causes the script to break

Trying to make a script that checks if one of three variables equals true, if any of the variables equals true then the if statement should trigger. For some reason the script only checks the first two variables and ignores the third, why is this? I’ve messed around with the script for a while now and nothing I do seems to allow for a third or in the if statement.

``````while true do wait(0.005)
if (workspace.GPlate1.Detect.Value.Value==true or workspace.GPlate2.Detect.Value.Value==true or workspace.NPlate1.Detect.Value.Value==true) and script.Parent.Position.Y < 26 then
script.Parent.Position = script.Parent.Position - Vector3.new(0,-0.5,0)
else if script.Parent.Position.Y > 7.5 then
script.Parent.Position = script.Parent.Position + Vector3.new(0,-0.5,0)
end
end
end
``````

Why do you think it only checks the first two? Boolean algebra is nice because it’s easy to see where a problem is just by printing a binary value.

``````while true do wait(0.005)
print(workspace.GPlate1.Detect.Value.Value==true)
print(workspace.GPlate2.Detect.Value.Value==true)
print(workspace.NPlate1.Detect.Value.Value==true)
print('and')
print(workspace.NPlate1.Detect.Value.Value==true)

if (workspace.GPlate1.Detect.Value.Value==true or workspace.GPlate2.Detect.Value.Value==true or workspace.NPlate1.Detect.Value.Value==true) and script.Parent.Position.Y < 26 then
script.Parent.Position = script.Parent.Position - Vector3.new(0,-0.5,0)
else if script.Parent.Position.Y > 7.5 then
script.Parent.Position = script.Parent.Position + Vector3.new(0,-0.5,0)
end
end
end
``````

Try this. If any one of the first print statements evaluates as true, and the print statement after ‘and’ also evaluates as true then the clause after your if will run.

I feel a bit idiotic for not waiting a small amount of time before posting this because I figured out that the value was not being set to true, though I still do not know why, the script is working fine but my other script is not.

(said script that is meant to set the third value to true)

``````local function Detector(Name)
for _, descendant in pairs(workspace:GetDescendants()) do
if descendant.Name == Name then
local magnitude = (script.Parent.Position-descendant.Position).Magnitude
if magnitude < 4 then
script.Parent.Value.Value=true
else
script.Parent.Value.Value=false
end
end
end
end
while true do wait(0.1)
Detector("NEUTRAL")
end
``````

Difficult to diagnose without knowing more about your project. But in a similar vein to what I suggested above, you could print script.Parent.Value.Value in either case if it changes (and magnitude). That should give insight into where the problem is.