Help with pet equip script

Hi everyone I have wrote a script for a pet equip system and it is in with my leader stats so ignore that part but anyways. I am trying to make a system that equips my pets I have and the hatching system works and everything is pretty good and works. But my problem is that I have the script to equip the pets in my leader stats and it will not equip the pet. I will change the value of the equipped pet but nothing happens. Thank you for your help and here is my script:

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 attachmentCharacter = Instance.new("Attachment")
	attachmentCharacter.Visible = false
	attachmentCharacter.Name = "attachmentCharacter"
	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 allignPosition = Instance.new("AlignPosition")
	allignPosition.MaxForce = 25000
	allignPosition.Attachment0 = attachmentPet
	allignPosition.Attachment1 = attachmentCharacter
	allignPosition.Responsiveness = 25
	allignPosition.Parent = pet
	
	local allignOrientation = Instance.new("AlignOrientation")
	allignOrientation.MaxTorque = 25000
	allignOrientation.Attachment0 = attachmentPet
	allignOrientation.Attachment1 = attachmentCharacter
	allignOrientation.Responsiveness = 25
	allignOrientation.Parent = pet

	pet.Parent = character
end

end

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

local leaderstats = Instance.new("Folder")
leaderstats.Name = "leaderstats"
leaderstats.Parent = player

local cash = Instance.new("IntValue")
cash.Name = "Cash"
cash.Value = 10000
cash.Parent = leaderstats

local Inventory = Instance.new("Folder")
Inventory.Name = "PetInventory"
Inventory.Parent = player

local equippedPet = Instance.new("StringValue")
equippedPet.Name = "EquippedPet"
equippedPet.Parent = player

player.CharacterAdded:Connect(function(char)
	if game.ReplicatedStorage:WaitForChild("Pets"):FindFirstChild(equippedPet.Value) then
		equipPet(player,game.ReplicatedStorage:WaitForChild("Pets"):FindFirstChild(equippedPet.Value):Clone())
	end
end)

equippedPet.Changed:Connect(function()
	if equippedPet.Value == nil then
		if game.ReplicatedStorage:WaitForChild("Pets"):FindFirstChild(equippedPet.Value) then
			equipPet(player,game.ReplicatedStorage:WaitForChild("Pets"):FindFirstChild(equippedPet.Value):Clone())
		end
	end
end)

end)

Have you tried putting prints in to confirm the process path is as you expect?

pretty sure this should be

if pet ~= nil and character ~= nil then

and

should be

if equippedPet.Value ~= nil then

I fixed it and it still did not work I will change the value of the equipped pet and nothing happens

I also added prints throughout the script and none of them printed when I changed the value of the equippedPet

Would you please update the post with the changed scripts (with prints in) and the output of the test run.