Conditional statement not working

  1. What do you want to achieve?

I want some code to execute when a part is in a certain orientation.

  1. What is the issue?

Even if the part is in the right orientation it won’t execute the code.

  1. What solutions have you tried so far?

I’ve tried looking for solutions on the forum but none of the solutions seem to work.


if script.Parent.Parent == game.Workspace then
	moveItem(Car, P1)
	moveItem(Car, P2)

	if Barrier.Orientation ==, 90.003, -81.998) then
		moveItem(Car, P3)

Are You sure that You don’t need to make the script wait for Barrier to reach certain orientation before using that if statement?

Your target orientation is way too specific. Because of the accuracy of numbers, comparing two marginally different Vectors or numbers (e.g 10.00001 ~= 10) won’t guarantee a 100% match.

Instead, try subtracting the current part’s orientation and your target orientation, and get their magnitude (or length). If the resulting magnitude is lower than a certain amount, you can somewhat say it is “exact”.

local isCloseToTargetOrientation = (Barrier.Orientation -, 90.003, -81,998)).Magnitude < 5