Does anyone know how to make a script that removes a players items from the backpack when a part is touched?
01 | local Players = game:GetService( "Players" ) |
02 |
03 | local Part = script.Parent |
04 |
05 | Part.Touched:Connect( function (Hit) |
06 | if Hit and Hit.Parent and Hit.Parent:FindFirstChildOfClass( "Humanoid" ) and Players:GetPlayerFromCharacter(Hit.Parent) then |
07 | local Player = Players:GetPlayerFromCharacter(Hit.Parent) |
08 | local Backpack = Player:FindFirstChildOfClass( "Backpack" ) |
09 |
10 | for index, child in ipairs (Backpack:GetChildren()) do |
11 | if child:IsA( "Tool" ) or child:IsA( "HopperBin" ) then |
12 | child:Destroy() |
13 | end |
14 | end |
15 | end |
16 | end ) |
1 | local part = script.Parent |
2 | part.Touched:Connect( function (otherPart) |
3 | local player = game.Players:GetPlayerFromCharacter(otherPart.Parent) |
4 | if player then |
5 | player.Backpack:ClearAllChildren() |
6 | end |
7 | end ) |
Closed as Not Constructive by Vulkarin, zblox164, green271, RAYAN1565, and ImageLabel
This question has been closed because it is not constructive to others or the asker. Most commonly, questions that are requests with no attempt from the asker to solve their problem will fall into this category.
Why was this question closed?