How to rotate CFrame in script

Hello, I am having some trouble with CFrames. I want to rotate the CFrame then when I move the CFrame I don’t want the rotation to go away.

In my code I do this:

-- In this part, I am rotating the model.
local modelCFrame = part:GetPrimaryPartCFrame()
part:SetPrimaryPartCFrame(modelCFrame * CFrame.Angles(0,math.rad(90), 0))
task.wait(0.1)
-- in this part I move the model. The only issue is when I move the model, It resets the rotation.
model:SetPrimaryPartCFrame(Vector3.new(0,0,0))

I am confused. What is “part” and what is “model” in this context? It seems like you have two separate models at play at the same time.

they are both the same thing. bassically this code is just crafted togeather to simulate a much easier to understand version of my actual issue. If you are able to fix this though it would supply a solution to the same more complex version

If they are the same thing:
CFrame are a combination of both the position of an object and it’s rotation. When you try setting the cframe to Vector3.new(0, 0, 0), it sets it to a position of 0, 0, 0 with no rotation.
If you want to keep rotation, do

model:SetPrimaryPartCFrame(CFrame.new(0, 0, 0) * CFrame.Angles(model.PrimaryPart.CFrame:ToEulerAnglesXYZ()))

This effectively adds the model’s previous rotation on top of the 0, 0, 0 coordinates.

1 Like

how would I make the rotation a specific value

It’s the same as the “orientation” property when you’re applying it to a new cframe without any previous angle. It’s in radians instead of degrees, though, so instead of doing

CFrame.Angles(0, 90, 0)

to turn it 90 degrees, you’d want to do

CFrame.Angles(0, math.rad(90), 0)
1 Like

Add this at the end

model.RootPart.CFrame += CFrame.fromEulerAnglesXYZ(X, Y, Z)
1 Like

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.