PivotTo not behave same with SetPrimaryPartCFrame

Hey, I’m trying to rotate an npc to a some target with CFrame.lookAt but it’s not working as intended. Here is my code :
npc:PivotTo(CFrame.lookAt(npc.Position,target.Position))
My npc looks a different positions but not the target. When I use this code instead:
npc:SetPrimaryPartCFrame(CFrame.lookAt(npc.Position,target.Position))
It’s working as intended. Is there anything that I’m making wrong?

You would use PivotTo for a model, which I can assume that means that “npc” is a model. Models do not have a .Position value, so if it’s not erroring, it could be returning nil or Vector3.new(0, 0, 0).

To get the current position of the model, do this:

npc:GetPivot().Position

Hopefully this helps :+1:

Yep I’m using npc:GetPivot().Position on my original code. Both codes are the same. Even when I try with SetPrimaryPartCFrame, I’m using GetPivot().Position. Only difference is setting the CFrame with PivotTo or SetPrimaryPartCFrame. I don’t want to use SetPrimaryPart because it will be deprecated but looks like I have to use it anyways. Thanks for your reply!

SetPrimaryPartCFrame() sets CFrame of a model based on set PrimaryPart, while PivotTo() sets CFrame of a part or model based on set pivot point.

image

You can try repositioning the pivot point to the position of your PrimaryPart to get the same outcome.

model.WorldPivot = model.PrimaryPart.CFrame
2 Likes

Thanks for the extra information! This situation was totally my fault tho. There was a pivot offset on my model, I removed it and it’s worked as intended. Changing world point didn’t help either when there is a pivot offset. Somehow SetPrimaryPartCFrame bypasses that offset i guess.

2 Likes

im sorry for bumping the post. im facing the same situation. how would you check for pivot offset?

There is a property called ‘Pivot Offset’ in the model properties. It displays the offset of the primary part, so you need to set a primary part for the model to make it visible.

1 Like