PcoWSkbVqDnWTu_dm2ix
We use cookies on this site to enhance your user experience
Collapse Sidebar

PrimaryPart

Model

BasePart

Points to the Model's primary part. The part is the BasePart that is used as a basis when positioning the model using the Model/MoveTo and Model/SetPrimaryPartCFrame functions.

Note when assigning the PrimaryPart that the part must be a BasePart that is descendant of the Model. If this is not the case, the PrimaryPart will be set to nil in Roblox studio, or produce an error if done so by a Script.

When dealing with models full of unanchored parts connected with joints such as Welds or Motor6Ds it is best practice to set the PrimaryPart to the root part of the assembly. Giving the example of a Player Character, this is the HumanoidRootPart.


Code Samples


SetPrimaryPartCFrame

In this code sample a Model is created with a simple arrangement of Parts. The PrimaryPart of this Model is then set, meaning Model:SetPrimaryPartCFrame can then be used.

To demonstrate SetPrimaryPartCFrame, a simple loop is then run which switches the model between two CFrames every second.

-- define two CFrames
local startCFrame = CFrame.new(0, 10, 0)
local endCFrame = CFrame.new(0, 15, 0) * CFrame.Angles(0, math.rad(90), 0)

-- create a simple model
local model = Instance.new("Model", game.Workspace)

local part = Instance.new("Part", model)
part.Size = Vector3.new(5, 1, 5)
part.Anchored = true
part.CFrame = startCFrame
part.BrickColor = BrickColor.new("Bright green")

local part2 = Instance.new("Part", model)
part2.Size = Vector3.new(5, 1, 1)
part2.Anchored = true
part2.CFrame = startCFrame * CFrame.new(0, 1, 0) * CFrame.Angles(0, math.rad(90), 0)
part2.BrickColor = BrickColor.new("Bright red")

-- set the model's PrimaryPart
model.PrimaryPart = part 

-- loop between the two CFrames
while true do
	wait(1)
	model:SetPrimaryPartCFrame(startCFrame)
	wait(1)
	model:SetPrimaryPartCFrame(endCFrame)
end