Is there a way to Destroy an instance through a table using something like table.find(table,"instance"):Destroy()?

I have a list of instances, that include the player’s backpack and the tool that they are holding. Is there a way to destroy a specific instance in a way such as the one below? (Although, it doesn’t work, which is why I am asking for help.)

table.find(Tools,"Wood"):Destroy()

Note, I reposted this because it didn’t get solved last time.

1 Like
if PLR.Backpack:FindFirstChild("TOOL") then
 PLR.Backpack['TOOL']:Destroy()
end
local Tools = {}

for i,v in pairs(game.Workspace:GetChildren()) do
 table.insert(Tools, v)
end

for i,v in pairs(Tools) do
 if v.Name == "Wood" then
v:Destroy()
 end
end

I considered this, but it would send an error if the player was holding the tool. Also, to give more context, this is to destroy wood, a resource, after a player crafts something. I could manually check to see if there is a tool that the player is holding, but I was wondering if there is a more straightforward approach to solving this problem.

sorry i forgot that tools get moved to the plr’s character when equipped

if PLR.Backpack:FindFirstChild("TOOL") then
 PLR.Backpack['TOOL']:Destroy()
elseif PLR.Character:FindFirstChild("TOOL") then
 PLR.Character['TOOL']:Destroy()
end

Use FindFirstChildOfClass() to find an instance of a particular class.

local Tool = Character:FindFirstChildOfClass("Tool")
if Tool then Tool:Destroy() end
1 Like