Pet falling from 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)

I removed parts of the script for length reasons. 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 need any explanation for anything, just ask.

maybe try to increase the maxforce ?

Did not seem to work. Thank you though.

Blockquote while true do
for i = 1,4 do
script.Parent.CFrame = script.Parent.CFrame + Vector3.new(0, 0.1, 0)
wait(0.1)
end
for i = 1,4 do
script.Parent.CFrame = script.Parent.CFrame + Vector3.new(0, -0.1, 0)
wait(0.1)
end
wait(0.1)
end

Put this script in the part. It should work.

Nope. Still just falls from character. Thank you though.