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

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

Asked by 2 years ago

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)
0
This error is what it is, `Pet.PrimaryPart` is missing, primary part should be the root part of the model imKirda 4491 — 2y
0
on line 39 put Pet.PrimaryPart = Pet:FindFirstChildWhichIsA("Part",true) or something like that for an easy fix greatneil80 2647 — 2y
0
There is no primarypart. It is basically the main part for positioning or tweening of a model AProgrammR 398 — 2y

1 answer

Log in to vote
0
Answered by 2 years ago

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 :)

Ad

Answer this question