Hey there. I have made a pet equipping system for my simulator game, but for an unknown reason every time you equip a pet, it duplicates more than one time. For instance, let’s say I equip my dog, it works fine, but then I equip my cat. Instead of only having one cat equipped, I get an additional cat. This can happen infinitely, so if I equip my dog again i’ll have three dogs equipped instead of the intended one. I have tried Reviewing and fixing the code myself multiple times but can’t seem to find an answer.
module.EquipPet = function(petfolder, event, event2, plr, petinfo, pets, FailedEvent)
event.OnServerEvent:Connect(function(plr, nameofpet)
local Inventory = plr:FindFirstChild("Pets")
if #plr.Character:WaitForChild("EquippedPets"):GetChildren() == 1 then
for _, pet in pairs (petfolder:GetChildren()) do
pet:Destroy()
end
elseif (Inventory:FindFirstChild(nameofpet)) and #plr.Character:WaitForChild("EquippedPets"):GetChildren() == 0 then
task.delay(.5, function()
Inventory[nameofpet]:Clone().Parent = plr.Character.EquippedPets
end)
end
end)
event2.OnServerEvent:Connect(function()
if #plr.Character:WaitForChild("EquippedPets"):GetChildren() == 1 then
for _, pet in pairs(petfolder:GetChildren()) do
pet:Destroy()
end
end
end)
end
Thanks in advanced!