Or operator not working as accordingly

I have an if statement that detects if the humanoid’s moving direction is either -1 or 1 in the x axis but the statement is still ran even if the moving direction is not -1 or 1.

print("Move Direction: " .. humanoid.MoveDirection.X)

if humanoid.MoveDirection.X == -1 or 1 then
	print(true)
end

image

try:

print("Move Direction: " .. humanoid.MoveDirection.X)

if humanoid.MoveDirection.X == -1 or humanoid.MoveDirection.X == 1 then
	print(true)
end

You can also simplify this down to:

if math.abs(humanoid.MoveDirection.X) == 1 then -- takes the absolute value of the MoveDirection X Coordinate (this will always be positive)
3 Likes

Thanks, it did work but do you know why I can’t just use or in between two values instead?

Because the first way you were doing it checks if humanoid.MoveDirection.X == -1 which is good, but then you do or 1 so you’re just checking for 1 which is true because lua only evaluates false and nil as falsy

1 Like

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.