Does anyone know how to make a script that removes a players items from the backpack when a part is touched?
COMMUNITY QUESTION
I need help making a script that removes a players items from the backpack when a part is touched?
2 answers
local Players = game:GetService("Players")
local Part = script.Parent
Part.Touched:Connect(function(Hit)
if Hit and Hit.Parent and Hit.Parent:FindFirstChildOfClass("Humanoid") and Players:GetPlayerFromCharacter(Hit.Parent) then
local Player = Players:GetPlayerFromCharacter(Hit.Parent)
local Backpack = Player:FindFirstChildOfClass("Backpack")
for index, child in ipairs(Backpack:GetChildren()) do
if child:IsA("Tool") or child:IsA("HopperBin") then
child:Destroy()
end
end
end
end)
3 comments
0
Thanks!
0
He's not going to learn if you just give him the answer
0
I explained how in comments before.
local part = script.Parent
part.Touched:Connect(function(otherPart)
local player = game.Players:GetPlayerFromCharacter(otherPart.Parent)
if player then
player.Backpack:ClearAllChildren()
end
end)
This discussion is preserved as it was. New answers, comments, and votes are closed.

2 comments
https://scriptinghelpers.org/help/how-post-good-questions-answers
Need a touched event on the part, use a conditional statement to see if what hit the part is a player, then use a generic loop to destroy the tools in the players' backpack.