Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
1

Moving an entire model with SetPrimaryPart?

Asked by 7 years ago

could anyone expand on how I could move an entire model? People told me to use:

model:SetPrimaryPartCFrame(workspace.brickek.CFrame)

But how does that set the Primary Part and how does it move the object?

2 answers

Log in to vote
1
Answered by
CootKitty 311 Moderation Voter
7 years ago
Edited 7 years ago

SetPrimaryPartCFrame sets the Primary Part of the model's CFrame to the argument passed into the function, and everything else in the model moves relative to that PrimaryPart.

This should work. However, make sure you set the primary part!

You can do this in the properties of the model, or via code.

model.PrimaryPart = model.PartYouWantToSetPrimaryPartAs
0
Please add more content to your answers, to make sure they are clear to the person who is asking the question. abnotaddable 920 — 7y
Ad
Log in to vote
0
Answered by 7 years ago
Edited 7 years ago

SetPrimaryPartCFrame is a method, it requires a model.
SetPrimaryPartCFrame sets the Primary part CFrame.
CFrame, is a data type that represents a position and orientation in 3D space.
Models do not have a CFrame. Thats why you have to use SetPrimaryPartCFrame.
This is where you use model:SetPrimaryPartCFrame() e.g:

local model = workspace.model
model:SetPrimaryPartCFrame()

However, you need to make sure there is a PrimaryPart. To do this we can do something like this:

local model = workspace.model
model.PrimaryPart = model.Part --model.Part is just the path to the object

Once we have that there is one final thing, setting the Desired CFrame. To create a CFrame we use CFrame.new(), for example:

local DesiredCFrame = CFrame.new() -- this creates the default CFrame of 0,0,0

However, you will want to customize this CFrame:

local DesiredCFrame = CFrame.new(2,10,2) --this creates a CFrame at 2(X)10(Y)2(Z)

Now, :SetPrimaryPartCFrame() has two brackets at the end where we will put the Desired CFrame. We can do this by:

local DesiredCFrame = CFrame.new(2,10,2)
:SetPrimaryPartCFrame(DesiredCFrame)

Now we have this, we put it all together:

local model = workspace.model
model.PrimaryPart = model.Part
local DesiredCFrame = CFrame.new(2,10,2)
model:SetPrimaryPartCFrame(DesiredCFrame)

This is our finished code and will set the Primary Part's CFrame to the DesiredCFrame.
This will move the WHOLE model with the primary part.

Answer this question