Still have questions? Join our Discord server and get real time help.
0

# Problem with this rotation script?

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?

1
dyler3 1473
4 years ago

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.

0
I left a comment for you as another answer to put my script into lua format. whyOmustOitObeOme 2 — 4y
0
I updated it. That should work... dyler3 1473 — 4y
0
Hm, there's still a problem of the part being locked in place because of the script repeating. I'm going to need another if then statement like "if script.Parent.Parent.Rotation ~= Vector3.new(0, 0, 0) then", but that doesn't work. I really appreciate all your help, by the way. whyOmustOitObeOme 2 — 4y
0
Your welcome, but I have to go in a moment, so I probably won't be able to respond again until tomorrow, but I won't give up on this. Could you try to explain to me what your script is supposed to be doing exactly? dyler3 1473 — 4y
0
All it's supposed to do is keep a part's rotation at (0, 0, 0) without having the part lock up. whyOmustOitObeOme 2 — 4y
0
Oh, well that's a simple fix, I'll update the script. dyler3 1473 — 4y
0
Should work now. If not, then Idk what the heck is wrong dyler3 1473 — 4y
0
Finally! It works now. Thanks for all the help. whyOmustOitObeOme 2 — 4y
0
Haha, no prob! Sorry it took so long to fix the problem. dyler3 1473 — 4y
-3

@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)