Set Model to a specific rotation

How can I set a model to a specific rotation? I tried doing this:

model:PivotTo(model:GetPivot() * CFrame.Angles(0, math.rad(90), 0));

But this rotates the model by 90 every time. I want to fix the orientation of the model to 90 so that the model stays at 90 degrees until I change the math.rad(value) to something else.

2 Likes

That’s because you are using GetPivot() which is getting the updated Pivot every time. Instead, you would need to get it’s position only, excluding any rotation values.

You can do this like so:

local getPivot = model:GetPivot()
model:PivotTo(CFrame.new(getPivot.X, getPivot.Y, getPivot.Z) * CFrame.Angles(0,math.rad(90),0))
4 Likes

Since model:GetPivot() returns a new value every time you call it, I suggest doing something like this instead.

local originalPivot = model:GetPivot()

-- Every time you want to update the pivot you call this
model:PivotTo(originalPivot * CFrame.Angles(0, math.rad(90), 0))
1 Like

That wouldn’t change the new location though in case they are moving the model around. Which is why the method I posted above would work better for both cases.

That doesn’t work, even this:

model:PivotTo(CFrame.Angles(0, math.rad(90), 0));

gives me the same results

That should have worked. CFrame.new() has no rotation set. Which means you are setting it to be 90 every time. Not an additional 90, just simply always at 90.

You just need the position without the rotation, like @Dev_Ryan mentioned. You can replace the line you currently have with this one:

model:PivotTo(CFrame.Angles(0, math.rad(90), 0) + model:GetPivot().Position)

Ok, I don’t know if changing the WorldPivot has much of fault to do here but here is my full code to rotate everytime:

model.WorldPivot = CFrame.new(model:GetBoundingBox().Position);
local pivot = model:GetPivot().Position
model:PivotTo(CFrame.new(pivot.X, pivot.Y, pivot.Z) * CFrame.Angles(0, math.rad(90), 0));