Pet does not connect to character

I am made a pet shop where players can buy pets and then equip them in their inventory. When the player equips a pet, it changes a string value in their character to the equipped pet name. When it is changed, it does a function:

game.Players.PlayerAdded:Connect(function(plr)



	
	local equippedPet = Instance.new("StringValue")
	equippedPet.Name = "EquippedPet"
	equippedPet.Parent = plr
	
	
	
	
	equippedPet.Changed:Connect(function()
		if equippedPet.Value ~= nil then
			if game.ReplicatedStorage:WaitForChild("Pets"):FindFirstChild(equippedPet.Value) then
				equipPet(plr,game.ReplicatedStorage:WaitForChild("Pets"):FindFirstChild(equippedPet.Value):Clone())
			end
		end
	end)
end)

Since the value is changed, it calls for a function that puts the pet to the players avatar using this function.

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
		if character.HumanoidRootPart:FindFirstChild("attachmentCharacter") then 
			character.HumanoidRootPart:FindFirstChild("attachmentCharacter"):Destroy() 
		end

		pet.Name = player.Name.."'s Pet"



		pet:SetPrimaryPartCFrame(character.HumanoidRootPart.CFrame)

		local modelSize = pet.PrimaryPart.Size

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

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

		local alignPosition = Instance.new("AlignPosition")
		alignPosition.MaxForce = 25000
		alignPosition.Attachment0 = attachmentPet
		alignPosition.Attachment1 = attatchmentCharacter
		alignPosition.Responsiveness = 30
		alignPosition.Parent = pet


		local alignOrientation = Instance.new("AlignOrientation")
		alignOrientation.MaxTorque = 25000
		alignOrientation.Attachment0 = attachmentPet
		alignOrientation.Attachment1 = attatchmentCharacter
		alignOrientation.Responsiveness = 30
		alignOrientation.Parent = pet
		pet.Parent = character
	end
end

The problem is, when it is equipped, the pet appears and just falls to the ground. I am guessing it has to do with the equipPet function and the attachments. What can I change?

If you Anchor the pet, does anything happen?

I have tried unachoring and anchoring the pet but it does not seem to produce any effect.

EDIT: I anchored all the parts in the model and now it just sits in one spot and does not follow the character at all. Instead, it sits in that one spot and moved up and down.