Model's PrimaryPart pivot doesn't work

I made a script to rotate a model

local model = script.Parent

local CFrameRotationn = -90

function newCFrame()
	
	local newCFrame= model.PrimaryPart.CFrame * CFrame.Angles(0, math.rad(CFrameRotationn), 0)
	model:SetPrimaryPartCFrame(newCFrame)
	
end

But when the model rotates it will not use the position where I put the PrimaryPart pivot but the default position of the pivot.

You should use :PivotTo() instead of :SetPrimaryPartCFrame()

When you get a BasePart’s CFrame using .CFrame, it will ignore any changes you’ve made to the BasePart’s PivotOffset. This is because you’ll need to use the :GetPivot() method that BaseParts and Models have to get its CFrame with the pivot offset applied:

local model = script.Parent

local CFrameRotationn = -90

function newCFrame()

	local newCFrame= model.PrimaryPart:GetPivot() * CFrame.Angles(0, math.rad(CFrameRotationn), 0)
	model:PivotTo(newCFrame)

end

What @ArpeaxVinheim said is correct too, you should use :PivotTo() to move a model. :SetPrimaryPartCFrame() has been deprecated, so it’s no longer recommended to use in new games

1 Like
local model = script.Parent

local CFrameRotationn = -90

function newCFrame()
	
	local newCFrame= model:PivotTo:(CFrame.Angles(0, math.rad(CFrameRotationn), 0)
	model:SetPrimaryPartCFrame(newCFrame)
end

I’m not a hundred percent sure this will work, but I’m pretty confident in it.

1 Like