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

GetPrimaryPartCFrame

Returns the CFrame of the Model's Model/PrimaryPart.

This function is equivalent to the following.

Model.PrimaryPart.CFrame

Note this function will throw an error if no primary part exists for the Model. If this behavior is not desired developers can do the following, which will be equal to nil if there is no primary part.

local cFrame = Model.PrimaryPart and Model.PrimaryPart.CFrame

Returns

Return Type Summary

Code Samples


Rotating a Model

The following code demonstrates how GetPrimaryPartCFrame and SetPrimaryPartCFrame can be used to rotate a model.

A simple model is created in the Workspace and a loop is started that will rotate the model 10 degrees around the Y axis every 0.2 seconds.

local startPosition = Vector3.new(0, 10, 0)

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

local part1 = Instance.new("Part")
part1.Size = Vector3.new(4, 4, 4)
part1.CFrame = CFrame.new(startPosition)
part1.Anchored = true
part1.BrickColor = BrickColor.new("Bright yellow")
part1.Parent = model

local part2 = Instance.new("Part")
part2.Size = Vector3.new(2, 2, 2)
part2.CFrame = part1.CFrame * CFrame.new(0, 3, 0)
part2.Anchored = true
part2.BrickColor = BrickColor.new("Bright blue")
part2.Parent = model

-- set the primary part
model.PrimaryPart = part1
model.Parent = game.Workspace

while true do
	local primaryPartCFrame = model:GetPrimaryPartCFrame()
	local newCFrame = primaryPartCFrame * CFrame.Angles(0, math.rad(10), 0)
	model:SetPrimaryPartCFrame(newCFrame)
	wait(.2)
end