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

How to remove a specific item in the backpack?

Asked by 6 years ago

I want to remove an item called "gun" from my backpack when i pass through a transparent part. How do you do this. I have found code to delete the entire inventory, but i would like to just delete the specific item.

0
Try, game.Players.LocalPlayer.Backpack:FindFirstChild("gun"):Destroy() btdawesome 0 — 6y

1 answer

Log in to vote
0
Answered by
mattscy 3725 Moderation Voter Community Moderator
6 years ago
Edited 6 years ago

You could try this in a script inside the transparent part:

local itemName = "gun"
script.Parent.Touched:Connect(function(hit)
    local plr = game.Players:GetPlayerFromCharacter(hit.Parent)
    if plr then
        local gun = plr.Backpack:FindFirstChild(itemName) or plr.Character:FindFirstChild(itemName)
        if gun then
            gun:Destroy()
        end
    end
end)
Ad

Answer this question