Pet System Problem

Right now I have a semi-working pet system and to make it fully working I need the Equip to work. Right now it is working but when the equip button is hit, it is not checking correctly. I will send the important parts of my code and hopefully you can help me out!

game.Players.LocalPlayer.PetInventory.ChildAdded:Connect(function()
for i,PlayerPetString in pairs(game.Players.LocalPlayer.PetInventory:GetChildren()) do
	for j,FolderName in pairs(game.ReplicatedStorage:GetChildren()) do
			for k,Pet in pairs(FolderName:GetChildren()) do
			if PlayerPetString.Name == Pet.Name then
					PetFound = false
				for z,Frame in pairs(game.Players.LocalPlayer.PlayerGui["Tapping Heroes"].Pets.Pets:GetChildren()) do
						if Pet.Name == Frame.Name then
						PetFound = true
					end
				end
				if not PetFound then
					addtoFrame(Pet)
					if PlayerPetString.Value == "Equipped" then
					if Pet.Parent == game.ReplicatedStorage.CommonPets then
						game.ReplicatedStorage.CommonFollow:FireServer(Pet)
					end
					if Pet.Parent == game.ReplicatedStorage.UncommonPets then
						game.ReplicatedStorage.UnCommonFollow:FireServer(Pet)
					end
					if Pet.Parent == game.ReplicatedStorage.RarePets then
						game.ReplicatedStorage.RareFollow:FireServer(Pet)
					end
					if Pet.Parent == game.ReplicatedStorage.LavaPets then
						game.ReplicatedStorage.LavaFollow:FireServer(Pet)
					end
					if Pet.Parent == game.ReplicatedStorage.DesertPets then
						game.ReplicatedStorage.DesertFollow:FireServer(Pet)
					end
					if Pet.Parent == game.ReplicatedStorage.WaterPets then
						game.ReplicatedStorage.WaterFollow:FireServer(Pet)
							end
						end
					local PetName = game.Players.LocalPlayer.PlayerGui["Tapping Heroes"].Pets.Pets[Pet.Name].PetName.Text
					UnEquip.MouseButton1Click:Connect(function(hit)
						if Pet.Name == PetName.Text and PlayerPetString.Value == "Equipped" then
						for i,Pet in pairs(workspace[game.Players.LocalPlayer.Name.."'s equipped pets"]:GetChildren()) do
								if Pet.Name == PetName.Text then
							game.Players.LocalPlayer.PlayerGui["Tapping Heroes"].Pets.PetStats.Clicks.PetsEquipped.Text = ("x"..game.ReplicatedStorage.Clicks.Value)
							print(Pet)
							local Name = game.Players.LocalPlayer.Name
								game.ReplicatedStorage.UnEquip:FireServer(Pet,Name)
							end
							end
							if IntValue >= 1 then
							MaxNumberPets = IntValue - 1
								print(MaxNumberPets)
								end
						end
					end)
					Equip.MouseButton1Click:Connect(function()
						if Pet.Name == PetName then
							print(PetName)
						if Pet.Parent == game.ReplicatedStorage.CommonPets then
							game.ReplicatedStorage.CommonFollow:FireServer(Pet)
						end
						if Pet.Parent == game.ReplicatedStorage.UncommonPets then
							game.ReplicatedStorage.UnCommonFollow:FireServer(Pet)
						end
						if Pet.Parent == game.ReplicatedStorage.RarePets then
							game.ReplicatedStorage.RareFollow:FireServer(Pet)
						end
						if Pet.Parent == game.ReplicatedStorage.LavaPets then
							game.ReplicatedStorage.LavaFollow:FireServer(Pet)
						end
						if Pet.Parent == game.ReplicatedStorage.DesertPets then
							game.ReplicatedStorage.DesertFollow:FireServer(Pet)
						end
						if Pet.Parent == game.ReplicatedStorage.WaterPets then
							game.ReplicatedStorage.WaterFollow:FireServer(Pet)
								end
								end
					end)
				end
			end
		end
	end
end

end)

If I am firing the server then it would have to be. So yes

oh yeah I am not smart oops.

can you put the mouse click action of the equip button outside of the child added function? maybe it does not run because it is inside a function that only runs sometimes

It equips the pets my problem is, it equips all the pets that they have instead of jsut that one.