✓ Accepted answer
Here You are.
EXAMPLE 1: You want to remove only some tools, defined by names
It will remove "ToolName1" and "ToolName2" from BackPack
local toremove = {"ToolName1", "ToolName2"}
local players = game.Players:GetChildren()
function RemoveFromBackpack(bp)
for _, i in pairs(toremove) do
if bp:FindFirstChild(i) then
bp[i]:Destroy()
end
end
end
if type(players) == "table" then
for _, i in pairs(players) do
if i:FindFirstChild("Backpack") then
RemoveFromBackpack(i.Backpack)
end
end
else
if players:FindFirstChild("Backpack") then
RemoveFromBackpack(players.Backpack)
end
end
EXAMPLE 2: You want only to remove some count of tools
It will remove 3 tools from backpack
local count = 3
local players = game.Players:GetChildren()
function RemoveFromBackpack(bp)
for i = 1, count, 1 do
if bp:GetChildren()[i] ~= nil then
bp:GetChildren()[i]:Destroy()
end
end
if type(players) == "table" then
for _, i in pairs(players) do
if i:FindFirstChild("Backpack") then
RemoveFromBackpack(i.Backpack)
end
end
else
if players:FindFirstChild("Backpack") then
RemoveFromBackpack(players.Backpack)
end
end