Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
COMMUNITY QUESTION

Anyone know how to fix this? Model:SetPrimaryPartCFrame() failed because no PrimaryPart has been set

Error: Model:SetPrimaryPartCFrame() failed because no PrimaryPart has been set, or the PrimaryPart no longer exists. Please set Model.PrimaryPart before using this.

local RS = game:GetService("ReplicatedStorage")

local Events = RS.Events
local Pets = RS.Pets

local PetCreate = Events.PetCreate

local tab = {}

function CreatePet(player, Index)
local character = player.Character or player.CharacterAdded:Wait()

if character.PrimaryPart:FindFirstChild("Attachment") then
	character.PrimaryPart:FindFirstChild("Attachment"):Destroy()
end

local Pet = Pets[Index]:Clone()

local AttachA = Instance.new("Attachment")
AttachA.Parent = Pet.PrimaryPart

local AttachB = Instance.new("Attachment")
AttachB.Position = Vector3.new(3,3,0)
AttachB.Parent = character.PrimaryPart

local AlignPosition = Instance.new("AlignPosition")
AlignPosition.Attachment0 = AttachA
AlignPosition.Attachment1 = AttachB

local AlignOrientation = Instance.new("AlignOrientation")
AlignOrientation.Attachment0 = AttachA
AlignOrientation.Attachment1 = AttachB

AlignPosition.MaxForce = 30000
AlignOrientation.MaxTorque = 30000

AlignPosition.Parent = Pet.PrimaryPart
AlignOrientation.Parent = Pet.PrimaryPart

Pet:SetPrimaryPartCFrame(character.PrimaryPart.CFrame)
Pet.Parent = workspace
tab[player] = Pet
end

PetCreate.OnServerEvent:Connect(function(player,Index)
if not tab[player] then
	CreatePet(player, Index)
else
	
	local prevPet = tostring(tab[player])
	
	tab[player]:Destroy()
	tab[player] = nil
	
	if prevPet ~= Index then
		CreatePet(player, Index)
	end
end
PetCreate:FireClient(player, tab[player])
end)

3 comments

0

This error is what it is, Pet.PrimaryPart is missing, primary part should be the root part of the model

0

on line 39 put Pet.PrimaryPart = Pet:FindFirstChildWhichIsA("Part",true) or something like that for an easy fix

0

There is no primarypart. It is basically the main part for positioning or tweening of a model

1 answer

in the model properties is category named primarypart. click on it and select part that you want to be primary part and it will work. it is good at placement etc. it is recommended to be part that touches all parts in model :)

This discussion is preserved as it was. New answers, comments, and votes are closed.