I'm wondering how I would remove a certain tool when player touches the Brick, so far I have this Script:
function onTouch(hit) character = hit.Parent if game:GetService("Players"):GetPlayerFromCharacter(character) then player = game:GetService("Players"):GetPlayerFromCharacter(character) tools = player.Backpack for _,a in pairs(tools) do if a:IsA("Tool") or a:IsA("HopperBin") then a:remove() end end end end
This is what I've tried and it works, I'd just like to know how to remove a certain tool out of the Backpack, for example if I wanted to remove or destroy a tool called 'Pizza' without removing it from other players Backpack, just the player that touched the brick.
This will remove the tools that you choose from the players backpack however will not remove them if the tool is equipped.
tools={}--Put the tool(s) name in here. Remember to put the name in "" and separate them with , . script.Parent.Touched:connect(function(part) if part.Parent:FindFirstChild("Humanoid") then if game.Players:GetPlayerFromCharacter(part.Parent) then player=game.Players:GetPlayerFromCharacter(part.Parent) for i,v in pairs (player.Backpack:GetChildren()) do if v:IsA("Tool") or v:IsA("HopperBin") then for i,c in pairs (tools) do if v.Name==c then v:Destroy() end end end end end end)
This code will remove tools that are in the backpack or equipped:
tools={}--Put the tool(s) name in here. Remember to put the name in "" and separate them with , . function remove(tool) for i, d in pairs (tools) do if tool.Name==d then tool:Destroy() end end end script.Parent.Touched:connect(function(part) if part.Parent:FindFirstChild("Humanoid") then if game.Players:GetPlayerFromCharacter(part.Parent) then player=game.Players:GetPlayerFromCharacter(part.Parent) for i,v in pairs (player.Backpack:GetChildren()) do if v:IsA("Tool") or v:IsA("HopperBin") then remove(v) end end for i,v in pairs (part.Parent:GetChildren()) do if v:IsA("Tool") or v:IsA("HopperBin") then remove(v) end end end end end)