Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

I need help making a script that removes a players items from the backpack when a part is touched? [closed]

Asked by 6 years ago

Does anyone know how to make a script that removes a players items from the backpack when a part is touched?

0
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. Launderer 343 — 6y

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?

2 answers

Log in to vote
0
Answered by
Launderer 343 Moderation Voter
6 years ago
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)

0
Thanks! User#24235 0 — 6y
0
He's not going to learn if you just give him the answer Vulkarin 581 — 6y
0
I explained how in comments before. Launderer 343 — 6y
Ad
Log in to vote
0
Answered by 6 years ago
local part = script.Parent
part.Touched:Connect(function(otherPart)
    local player = game.Players:GetPlayerFromCharacter(otherPart.Parent)
    if player then
        player.Backpack:ClearAllChildren()
    end
end)