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

Help with this script that checks for rotation?

Asked by 9 years ago

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.

1 answer

Log in to vote
0
Answered by
gskw 1046 Moderation Voter
9 years ago

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
0
There's still a problem of the script playing even if the part's rotation is (0, 0, 0) when I tried your script out. whyOmustOitObeOme 7 — 9y
0
You're probably better off using a BodyGyro or whatever the Force object that stabilizes parts is called to preserve a rotation. adark 5487 — 9y
0
They were taken out of the game, as far as I can tell. As another note, when I call for the part's rotation along the x axis, I get a crazy number like 1.0900675562198e-007. Maybe that helps, I don't know. whyOmustOitObeOme 7 — 9y
Ad

Answer this question