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.
COMMUNITY QUESTION
How to remove a specific item in the backpack?
1 answer
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)
This discussion is preserved as it was. New answers, comments, and votes are closed.

1 comment
Try, game.Players.LocalPlayer.Backpack:FindFirstChild("gun"):Destroy()