Ok, so I have a script that checks to see if an objects rotation isn't (0, 0, 0), and if it isn't, it makes the object rotation (0, 0, 0). Here's the script:
while true do wait(0.01) if script.Parent.Parent.Rotation ~= Vector3.new(0, 0, 0) then -- script.Parent.Parent is the part I'm changing script.Parent.Parent.CFrame = CFrame.new(script.Parent.Parent.Position.X, script.Parent.Parent.Position.Y, script.Parent.Parent.Position.Z) * CFrame.Angles(0,0,0) end end
The script itself works in changing the rotation to (0, 0, 0), but for some reason, even if the rotation is (0, 0, 0), the script still plays. The part I'm working on has a bodyvelocity, and since this script loops every time, even if the rotation is (0, 0, 0), the part jolts from front to back because of the script playing so many times. I'm looking for a better "if then" statement that will correctly prevent the script from running if the part's rotation is (0, 0, 0), because mine apparently doesn't work.
A few tweaks have to be done.
You should not write script.Parent.Parent
again and again. Just save it to a variable.
Also, Vector3's are userdata values so ~= doesn't work well on them. You will have to compare their properties.
And finally, you don't have to use CFrame.new()
like that.
The final script will look like this:
local part = script.Parent.Parent -- script.Parent.Parent is the part I'm changing while wait() do -- Using wait() here, it will work and the 0.01 is unneccessary local rotation = part.Rotation if rotation.x ~= 0 or rotation.y ~= 0 or rotation.z ~= 0 then -- Changes here, too part.CFrame = CFrame.new(part.Position) * CFrame.Angles(0,0,0) -- Changes! end end