How can I remove tools from player backpack?

I know to clone tools into Backpack but I dont know how to destroy they afther. I mean I cant make :FindFirstChild(“tool”) inside Backpack and destroy it?

5 Likes

Do you want to remove all of them or just one?
For all of them:

local player = --path to player
local inventory = player.Backpack
for i,v in pairs(inventory:GetChildren()) do
if v.:IsA("Tool") then
v:Destroy()
end
end

Or you can call destroy for the tool you want.

1 Like

Yes is something like that I guess

1 Like

if youre cloning a tool and then destroy it , clone it like this:
local tool = (-tool path):Clone()
wait(3)
tool:Destroy – Example

1 Like

local tool = RS.tool
local player = game.Players.LocalPlayer

local cloneTool = tool:Clone()
CloneTool.Parent = player.Backpack
wait(1)
–now I need to get it from Backpack

You can either call the Destroy() method on the tool’s clone or you can reference the tool path and destroy it

only u need to type is
cloneTool:Destroy()

CloneTool is the same with different parents. No need to worry about it.

Ok I am working with one ImageButton and when I click on it he will clone one tool into Backpack but for destroy it I can use :FindFirstChild(“tool”)?

local tool = RS.tool
local player = game.Players.LocalPlayer

local cloneTool = tool:Clone()
CloneTool.Parent = player.Backpack
wait(1)
CloneTool:Destroy()
2 Likes

i dont recommend :FindFirstChild(“tool”) since youre said what tool means in the script , you can just :Destroy it

1 Like

Oh ok now I understand because CloneTool parent is Backpack.

1 Like

To remove all children from the backpack, use: Backpack:ClearAllChildren()

8 Likes

I used only for remove one tool and I did :FindFirstChild(“tool”):Destroy()

there’s a slight typo. for those who want to find a solution to DESTROYING ALL tools from inventory its this:

local player = --path to player
local inventory = player.Backpack
for i,v in pairs(inventory:GetChildren()) do
if v:IsA("Tool") then
v:Destroy()
end
end
1 Like

funny thing is i still come back to this everytime i forget

1 Like
local player = ---Player idk

for _ , v in pairs(player.Backpack:GetChildren()) do 
      if v:IsA("Tool") then
          v:Destroy()
      end
end

for _ , v in pairs(player.Character:GetChildren()) do 
      if v:IsA("Tool") then
          v:Destroy()
      end
end
1 Like

Backpack:ClearAllChildern()

and just loop through the character to remove all tools

1 Like