How Do I Delete Items In A Player's Backpack

Basically how do I delete items in a player’s backpack through a server script.

I tried doing this, but it doesn’t work and there are no errors

local items = player.Backpack:FindFirstChildOfClass("Tool")
		player.items:Destroy()
8 Likes
3 Likes

I think that’s removing a players items through a local script

1 Like

It should still nonetheless tell you how to delete items from a player’s backpack.

1 Like

Tools that are unequipped will be in the Backpack, and tools that are equipped will be within the character. If you want to delete a certain tool from the player (in the backpack and character), you could try doing this:

local itemName = "Cup" --Change this
if player.Backpack:FindFirstChild(itemName) and player.Backpack[itemName]:IsA("Tool") then
    player.Backpack.Cup:Destroy()
end --Destroy Non-Equipped tool in inventory / Backpack
if player.Character and player.Character:FindFirstChild(itemName) and player.Character[itemName]:IsA("Tool") then
    player.Character[itemName]:Destroy()
end --Destroy Equipped Tool

If you want to remove ALL tools in a backpack, you can do

for _, tool in ipairs(player.Backpack:GetChildren()) do
    if tool:IsA("Tool") then
        tool:Destroy()
    end
end --Deletes all tools from Backpack
if player.Character:FindFirstChildOfClass("Tool") then
    player.Character:FindFirstChildOfClass("Tool"):Destroy()
end --Deletes Equipped Tool
25 Likes

What do we reference player as since its a server script?

1 Like

Can you post your script so we can better help you?

1 Like

What is the player referenced as?

1 Like

local player = game:GetService(“Players”).LocalPlayer

3 Likes

Hello everyone, sorry for reviving the topic but I’m actually trying to use it myself but it keeps giving me this error and I can’t seem to find a solution to it


Thanks to everyone that can help. ~ Lama

2 Likes

do you know when you have the same tool like 5 item and when it destory it all gone how to make it only destory once

1 Like