Only rotating a CFrame on an axis without affecting its position

Hello!

So basically, I am having an issue rotating a CFrame 180º on the Y axis. I want it to kind of “snap” to the part, however it’s returning Position cannot be assigned to in the output.

Here’s the snippet causing the issue:

local cframe = CFrame.new(smallest) -- smallest is a vector3
if smallest == walls.wallN or smallest == walls.WallS then
	cframe = CFrame.Angles(0, math.rad(180), 0) -- Set the angle, BUT it moves it to 0,0,0
	cframe.Position = smallest -- causing the issue, returning the error.
end
model:SetPrimaryPartCFrame(cframe)

I’ve also tried using :ToWorldSpace() but it seems not to affect anything.

I think your setting the position to CFrame.new. Try smallest.CFrame.

1 Like

CFrames, like basically any other datatype execpt Instance and RaycastParams, are immutable.

You will want to multiply the cframe by CFrame.Angles(0, math.rad(180), 0)

local cframe = CFrame.new(smallest)*CFrame.Angles(0, math.pi/2, 0)
-- pi radians = 180 degrees
1 Like

The smallest variable is just a vector3, it’s not an actual part.