Making a part rotate to specific orientation

Ok so, I can do

part.CFrame *= CFrame.Angles(0, math.deg(90), 0)

to rotate a part by 90 degrees.
But how do I make a part be a specific rotation instead of adding to the current rotation? BasePart.Orientation doesn’t replicate so thats out of the window

2 Likes

I didn’t quite understand, do you want a part to rotate instead?

Hi StealthKing95!

To rotate a part TO a specific rotation you can use CFrame.new(PART POSITION) * CFrame.Angles(NEW ROTATION). I’ve provided an example below which will change a parts rotation using CFrame to a given rotation, and then after 5 seconds reset it back to the default 0,0,0 rotation.

local part = script.Parent;

local newPartRotation = CFrame.Angles(math.deg(15), math.deg(25), math.deg(95)) -- the new rotation we want the part to have
part.CFrame = CFrame.new(part.Position) * newPartRotation; -- changing part's cframe rotation

wait(5);

newPartRotation = CFrame.Angles(math.deg(0), math.deg(0), math.deg(0));
part.CFrame = CFrame.new(part.Position) * newPartRotation;

To read more about CFrame you can check out the wiki page here which has some pretty nifty examples that I think you would benefit from!

7 Likes