Roblox Studio error

Model:SetPrimaryPartCFrame() failed because no PrimaryPart has been set

What Model:SetPrimaryPartCFrame() failed because no PrimaryPart has been set means in Roblox Studio, the two things that cause it with the code that triggers each, and the fix for each one.

Updated 12 November 20263 min readErrorLuauWritten by

In short

SetPrimaryPartCFrame moves a model by moving its PrimaryPart, so it fails when the model has none. Either the PrimaryPart property was never set, or the part it pointed to was destroyed. The modern fix is model:PivotTo(cframe), which moves any model, with or without a PrimaryPart. SetPrimaryPartCFrame is deprecated, so switching also removes the warning.

On this page
  1. What it means
  2. Causes and fixes
  3. Fix it with RoCode
  4. Find the line
  5. Questions
  6. Sources

What the message means

Output (example)
ServerScriptService.Teleporter:9: Model:SetPrimaryPartCFrame() failed because no PrimaryPart has been set, or the PrimaryPart no longer exists. Please set Model.PrimaryPart before using this.

Models from the Toolbox and models you group yourself often have no PrimaryPart: it is only set if someone picks one in the Properties window.

GetPrimaryPartCFrame fails the same way. Its replacement is model:GetPivot().

Causes and fixes

Two things cause this error in practice. Each one below has the smallest code that triggers it, then the fix.

The model has no PrimaryPart

The PrimaryPart property is empty, so there is no part to move.

Breaks Script in ServerScriptService named Teleporter
local car = workspace:WaitForChild("Car")
local spawnPad = workspace:WaitForChild("SpawnPad")

-- Model:SetPrimaryPartCFrame() failed because no PrimaryPart has been set
car:SetPrimaryPartCFrame(spawnPad.CFrame + Vector3.new(0, 5, 0))

Use PivotTo. It moves the whole model by its pivot, which every model has.

Fixed Script in ServerScriptService named Teleporter
local car = workspace:WaitForChild("Car") :: Model
local spawnPad = workspace:WaitForChild("SpawnPad") :: BasePart

car:PivotTo(spawnPad.CFrame + Vector3.new(0, 5, 0))

Want the model to turn around one part, like the car body? Select the model, set PrimaryPart in the Properties window, and the pivot moves to that part.

The PrimaryPart was destroyed or fell away

If the part set as PrimaryPart is destroyed, or falls out of the world and is removed, the property goes back to nil. Code that worked at the start of the round then fails.

Breaks Script in ServerScriptService named GuardReset
local npc = workspace:WaitForChild("Guard")

-- works until HumanoidRootPart is gone
while true do
    npc:SetPrimaryPartCFrame(CFrame.new(0, 10, 0))
    task.wait(5)
end

Move it with PivotTo, and stop when the model itself is gone.

Fixed Script in ServerScriptService named GuardReset
local npc = workspace:WaitForChild("Guard") :: Model

while npc.Parent do
    npc:PivotTo(CFrame.new(0, 10, 0))
    task.wait(5)
end

Fix it in your place

Paste the error, RoCode fixes it in your place

Copy the line from Output and paste it here. RoCode opens the script it names in the place you have open in Studio, works out which of the causes above it is, and edits the code there instead of handing you a snippet to paste.

For example: ServerScriptService.Teleporter:9: Model:SetPrimaryPartCFrame() failed because no PrimaryPart has been set, or the PrimaryPart no longer exists. Please set Model.PrimaryPart before using this.

RoCode is an AI agent for Roblox Studio: it reads the scripts in the place you have open, finds the line and edits it there, and every change is an undo point. It runs on Windows or macOS with a desktop browser. Free to start, with free credits every day.

How to find the line that causes it

  1. Open Output (Window menu, or the Script tab), clear it with Ctrl+K (⌘K on Mac), and press Play.
  2. Find the first red line. It starts with the script's place in the Explorer and the line number, such as ServerScriptService.Shop:12:.
  3. Click the red line. Studio opens that script with the cursor on the failing line.
  4. Read the lines between Stack Begin and Stack End under it: they list the calls that led there, newest first, so you can see which function called the broken one.
  5. Still not sure which value is wrong? Add print(typeof(x), x) just above the line, or set a breakpoint on it and read the values in the Watch window.

Questions

What is the difference between PivotTo and SetPrimaryPartCFrame?

Both move every part of a model together. PivotTo uses the model pivot, which always exists, and is the current API. SetPrimaryPartCFrame needs a PrimaryPart and is deprecated.

How do I teleport a player character?

Use character:PivotTo(cframe) on the server. Characters have a PrimaryPart (HumanoidRootPart), but PivotTo works even while the character is still loading.

How do I set the PrimaryPart in a script?

model.PrimaryPart = model:FindFirstChild("Body") :: BasePart. The part must be inside the model.

Can RoCode fix it?

Yes. Paste the Output line into RoCode. It swaps the deprecated calls in your open place for PivotTo and GetPivot.

Sources and further reading

How the code was checked: every block marked Fixed passes Luau's strict type checker against Roblox's API definitions (luau-lsp, 12 November 2026), and every block marked Breaks compiles and fails only when it runs. The message wording was checked against the strings in Roblox Studio itself (macOS build installed on 12 November 2026) on 12 November 2026. A type check catches misspelt APIs and wrong types, not game logic, so playtest in Studio before you publish.

More Roblox errors

All Roblox Studio errors

Stop hunting errors line by line.

RoCode reads the scripts in your open place, fixes the error where it happens and tells you what it changed. Free every day, no card required.