There's a few different ways of doing this. Below I will provide you with a few different options depending on your wants and needs.
If you're looking to remove all the tools from a players backpack (this would not include anything equipped I'm doing this first because, you said remove all tools from the players backpack) you would use this sample. (This works)
01 | script.Parent.Touched:Connect( function (hit) |
02 | local humanoid = hit.Parent:FindFirstChild( "Humanoid" ) |
04 | for t, item in pairs (game.Players [ hit.Parent.Name ] .Backpack:GetChildren()) do |
05 | if item:IsA( "Tool" ) then |
If you're looking to remove everything including equipped tools you would use this.
01 | script.Parent.Touched:Connect( function (hit) |
02 | local humanoid = hit.Parent:FindFirstChild( "Humanoid" ) |
04 | for t, item in pairs (hit.Parent:GetChildren()) do |
05 | if item:IsA( "Tool" ) then |
09 | for t, item in pairs (game.Players [ hit.Parent.Name ] .Backpack:GetChildren()) do |
10 | if item:IsA( "Tool" ) then |
There's more than one way to do this so here's a code that does the same thing. Like I said you can make your selection. Depending on your wants and needs, the other ones are really good for using certain things like, lets say removing a certain "Sword" or something you can simply add a item.Name == "whatever your tool name is like I said sword"
The code below once again is only for removing tools in the backpack like you asked for!
02 | if hit = = nil then return end |
03 | local h = game.Players:GetPlayerFromCharacter(part.Parent) |
05 | local tool = h.Backpack:GetChildren() |
12 | script.Parent.Touched:connect(hit) |
I actually tested these, if you have any problems feel free to comment and let me know! I'm happy to help.