Pets won't follow me

My Pet: Model > Meshparts and PrimaryPart
Here’s the code that doesn’t work:

local function equipPet(player,pet)
	local character = player.Character
	if pet ~= nil and character ~= nil then
		if character:FindFirstChild(player.Name.."'s Pet") then
			character[player.Name.."'s Pet"]:Destroy()
		end
		pet.Name = player.Name.."'s Pet"

		pet:SetPrimaryPartCFrame(character.HumanoidRootPart.CFrame)

		local modelSize = pet.PrimaryPart.Size
		local attachmentCharacter = Instance.new("Attachment")
		attachmentCharacter.Visible = false
		attachmentCharacter.Parent = character.HumanoidRootPart
		attachmentCharacter.Position = Vector3.new(1, 1, 0) + modelSize

		local attachmentPet = Instance.new("Attachment")
		attachmentPet.Visible = false
		attachmentPet.Parent = pet.PrimaryPart

		local alignedPosition = Instance.new("AlignPosition")
		alignedPosition.MaxForce = 25000
		alignedPosition.Attachment0 = attachmentPet
		alignedPosition.Attachment1 = attachmentCharacter
		alignedPosition.Responsiveness = 25
		alignedPosition.Parent = pet

		local alignOrientation = Instance.new("AlignOrientation")
		alignOrientation.MaxTorque = 25000
		alignOrientation.Attachment0 = attachmentPet
		alignOrientation.Attachment1 = attachmentCharacter
		alignOrientation.Responsiveness = 25
		alignOrientation.Parent = pet

		pet.Parent = character
	end
end

Here’s the code which called the function: wait(5) equipPet(player, game.ReplicatedStorage.Pets.Dog:Clone())

Any ideas please let me know :slight_smile:

1 Like

What is the issue with the code? It seems to work.

2 Likes

My pet won’t follow me when I move