Character Destroyed When I destroy a tool?

Hello! I’m trying to remove tools from a player when they exit a level.

The problem is, that I realized that when you equip a tool it goes into your character, not your backpack. So I made it loop through all the tools in both backpack and the player’s character, but for some reason, if I try and remove it from the character using “:Destroy()”, it deletes the character.

local function exitMap(player)
	print(player.Name.." has exited the map.")
	for _, tool in pairs(player.Backpack:GetChildren()) do
		tool:Destroy()
	end
	
	for _, tool in pairs(player.Character:GetChildren()) do
		tool:Destroy()
	end
end
2 Likes

You’re not checking if the object IsA Tool and when it destroys the HumanoidRootPart (which is in the character), the character gets destroyed.

You could change it to:

for i, tool in pairs(Player.Character:GetChildren()) do
if tool:IsA(“Tool”) then
tool:Destroy()
end
end
2 Likes

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.