How to destroy tables

Context: I am trying to clear all possible tools from the player’s backpack.

local tool = game.Players.LocalPlayer.Backpack:GetChildren() -- we will take the tool away from the player
				tool:Destroy()

These lines of code result to error:


Is there a specific method to destroy a table? Thanks 100 in advance

you could try looping through the list and destroying each tool 1 by 1

local tools = game.Players.LocalPlayer.Backpack:GetChildren()

for _, tool in pairs(tools) do
        tool:Destroy()
end
1 Like

There should only be tools in a backpack; there’s no need to use a loop.

LocalPlayer.Backpack:ClearAllChildren()

this’ll remove every child of backpack.

1 Like

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