I made a script that's supposed to make an object have a constant rotation of (0, 0, 0), but it's not working right. Here's the script:
while true do wait(0.1) if script.Parent.Parent.Rotation ~= Vector3.new(0, 0, 0) then -- script.Parent.Parent is a part script.Parent.Parent.Rotation = Vector3.new(0, 0, 0) script.Parent.Parent.CFrame = CFrame.new(script.Parent.Parent.Value.Value) -- position the object to where it belongs (script.Parent.Parent.Value is a Vector3Value) end
Other important info: the part has a constant motion of 10 with a BodyVelocity.
The problem with this is that the script, even if the part's rotation is (0, 0, 0), still plays and locks the part into a fixed position because the script keeps looping. I'm wondering what's wrong with this script, because to me it's fine. There's no errors in the output. Any help?
It's happening because whenever you use CFrame, it resets the rotation back to default. To fix it, you want to make the CFrame part look like this:
script.Parent.Parent.CFrame = CFrame.new(script.Parent.Parent.Value.Value)*CFrame.Angles(0,0,0)
This should set the rotation right. If you have any trouble setting the rotation to something else, you'll want to note that it is measured in radians. To switch normal values to radians do something like this:
CFrame.Angles(math.rad(10),math.rad(10),math.rad(10))--Change the 10's to whatever you want that rotation to be set to.
Anyways, this should work. If you have any questions or problems with this, please leave a comment below. Hope I helped :P --- Well i'm not sure what you or I did wrong, but that should've worked. Anyways, i'll just paste the entire code for your convenience:
while true do wait(0.1) 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) --Try this now end
This should work now. Just copy and place that in place of what you previously had.
@dyler3
I tried what you said, but now the part isn't even do anything. Whenever the rotation changes, the script doesn't do anything about it. This is what I tried:
while true do wait(0.1) if script.Parent.Parent.Rotation ~= CFrame.Angles(math.rad(0),math.rad(0),math.rad(0)) then script.Parent.Parent.Rotation = CFrame.Angles(math.rad(0),math.rad(0),math.rad(0)) -- setting the rotation to (0, 0, 0) script.Parent.Parent.CFrame = CFrame.new(script.Parent.Parent.Value.Value)*CFrame.Angles(0,0,0) end