How can i get it to remove only 3 tools i want it to remove
for i,v in pairs(game.Players:GetChildren()) do --Get all children of players Backpack = v:FindFirstChild("Backpack",true) if Backpack ~= nil then --Check if the child has a backpack c = Backpack:GetChildren() --Get the children of the backpack for i = 1,#c do c[i]:Destroy() --Use Destroy method instead end end end)
Here You are. EXAMPLE 1: You want to remove only some tools, defined by names It will remove "ToolName1" and "ToolName2" from BackPack
-- SETTINGS local toremove = {"ToolName1", "ToolName2"} -- NAMES OF TOOLS TO REMOVE local players = game.Players:GetChildren() -- HERE PLACE ARRAY HOLDING PLAYERS OR PLAYER INSTANCE WHICH WILL LOSE HIS TOOLS -- SCRIPT 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
-- SETTINGS local count = 3 -- HOW MUCH TOOLS WILL BE REMOVED local players = game.Players:GetChildren() -- HERE PLACE ARRAY HOLDING PLAYERS OR PLAYER INSTANCE WHICH WILL LOSE HIS TOOLS -- SCRIPT 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