Set Primary Part CFrame

Hello why when I do :SetPrimaryPartCFrame, my object doesn’t move? even the primary part CFrame does’t move. What’s worse for me is that it works if I use on command bar but in game it doesn’t work.

Current script, very simple just for testing :

local flags = workspace["US Flag"]
local flag = flags.AnimatedFlag

flag:SetPrimaryPartCFrame(flag.PrimaryPart.CFrame + Vector3.new(0, 20 , 0))
1 Like

Can you show your Script please?

I already edit my topic. The weird thing is when I try to run the script from command bar it works, but when I play in game, it doesn’t work again.

2 Likes

You may be using a Part instead of a Model

It only works on the Model, not a Part

local flags = workspace["US Flag"] --The Model?
local flag = flags.AnimatedFlag -- The Child?

flags:SetPrimaryPartCFrame(flags.PrimaryPart.CFrame + Vector3.new(0, 20 , 0))

If not the case, check if you have a Part Assigned as the PrimaryPart

1 Like

Prob it’s because u used CFrame instead Position
Try this:

flag:SetPrimaryPartCFrame(flag.PrimaryPart.Position + Vector3.new(0, 20 , 0))

SetPrimaryPartCFrame is deprecated and should not be used for new work. Instead you should use PivotTo to move the model, and GetPivot to get the current position of the model (The blue dot when you edit a model in Studio).

flag:PivotTo(flag:GetPivot() + Vector3.new(0, 20, 0))

And this topic should not have been bumped up.

1 Like

Also you should know that PivotTo uses CFrames and not Vector3s, so the correct way to do it would be

flag:PivotTo(flag:GetPivot() * CFrame.new(0, 20, 0))
1 Like

You can use + Vector3.new, rather than * CFrame.new, the only difference is that +Vector3, will not be in the 3d space of the cframe but rather will be in world space.