Pet following problem

I am equipping a non humanoid pet, but sometimes the BasePart of the pet model disappears when I equip it, leaving only the Humanoid. I have not understood this problem, and what is the reason for it
This is my client code.
1.This is a client-side script
function Manage_PetFollow.Equip(PetName,UUID)

local Model = game:GetService("ReplicatedStorage").PetModel:FindFirstChild(PetName)

if Model then
	local PetModel = RF_PetEquip:InvokeServer(Model,UUID)
	if PetModel then
		PetModel:PivotTo(Player.Character.HumanoidRootPart.CFrame)
		local characterAt = Instance.new("Attachment",Player.Character.HumanoidRootPart)


		characterAt.Visible = false

		local PetAt = Instance.new("Attachment",PetModel.PrimaryPart)
		PetAt.Position = Vector3.new(0,1.5,0)
		PetAt.Visible = false


		local AlignPosition = Instance.new("AlignPosition",PetModel.PrimaryPart)

		AlignPosition.Mode = Enum.PositionAlignmentMode.OneAttachment
		AlignPosition.Attachment0 = PetAt
		AlignPosition.Responsiveness = 30

		AlignPosition.MaxForce = 25_0000

		local AlignOrientation = Instance.new("AlignOrientation",PetModel.PrimaryPart)

		AlignOrientation.Attachment0 = PetAt
		AlignOrientation.Attachment1 = characterAt
		AlignOrientation.Responsiveness = 30
		AlignOrientation.MaxTorque = 25_0000



	end



end

end

RunService.RenderStepped:Connect(function()
local PetFodler = workspace.Pets:FindFirstChild(Player.Name)

if action == true and  PetFodler and #PetFodler:GetChildren() > 0 then

	local Count = #PetFodler:GetChildren()
	local P = Manage_PetFollow.CalculateFollowPosition(Character,Count,5)
	for i,v in pairs(PetFodler:GetChildren()) do
		
		v.PrimaryPart.AlignPosition.Position = P[i]


	end
end

end)

function Manage_PetFollow.CalculateFollowPosition(Character, petCount, spacing)
local playerPosition = Character.HumanoidRootPart.Position
local playerForward = Character.HumanoidRootPart.CFrame.LookVector
local playerRight = Character.HumanoidRootPart.CFrame.RightVector

local followPositions = {}

local maxColumns = 4 
local maxRows = math.ceil(petCount / maxColumns)

local offsetX = (maxColumns - 1) * spacing / 2 

for i = 1, petCount do
	local row = math.ceil(i / maxColumns)
	local column = (i - 1) % maxColumns

	local rowPetCount = math.min(petCount - (row - 1) * maxColumns, maxColumns)


	local xOffset = (column - (rowPetCount - 1) / 2) * spacing
	local zOffset = (1-row) * spacing

	
	local followPosition = playerPosition - playerForward * 5 + playerRight * xOffset + playerForward * zOffset
	followPositions[i] = followPosition
end

return followPositions

end

2.This is my server-side script。
RF_PetEquip.OnServerInvoke = function(plr,PetModel,UUID)

local Pet = PetModel:Clone()
Pet.Parent = workspace.Pets:WaitForChild(plr.Name)

Pet.PrimaryPart:SetNetworkOwner(plr)
Pet.Name = UUID

return Pet

end

1 Like