I have a pet system, and when i try to unequip the pet everything works just fine, the text changes to unequip, but i get an error in the output saying "Main.87 attempt to index nil with 'Destroy'" and it doesnt unequip the pet. I dont know how to fix this pls helppp
game.ReplicatedStorage.Remotes.UnequipPet.OnServerEvent:Connect(function(player, pet) if player.Character.Humanoid.Health ~= 0 then player. Character:FindFirstChild(pet):Destroy() end end)
This part of the code is causing the problem: Character:FindFirstChild(pet)
-- If the pet, is called pet. It would be Character:FindFirstChild("Pet")
-- It expects a string to find.
If this still does not work, it cant find the pet. Try this:
-- Locate player -- local Character = player.Character if Character:FindFirstChild("Pet") then local Pet = Character:FindFirstChild("Pet") Pet:Destroy() else warn("Player does not have a pet / pet not found!") -- This will output a warning, if there is no pet end
i never use :Destroy(), it often ruins things for no reason. I would make a folder in replicated storage that unused things go in for example:
local folder = game.ReplicatedStorage.Folder Pet.Parent = folder