Does anyone know how to clear all players inventories in my game?
i wanna make it so when a script enabled itll clear all peoples backpacks
Using a for i, v in pairs loop you can get all the players using game.Players:GetPlayers(), and then you can get everything inside every Player’s Backpack using GetChildren(), & destroying everything inside it
for _, Player in pairs(game.Players:GetPlayers()) do
for _, Tool in pairs(Player.Backpack:GetChildren()) do
if Tool:IsA("Tool") then
Tool:Destroy()
end
end
end
Use Humanoid:UnequipTools to forcefully return any Tools to the player’s backpack before clearing the backpack. The backpack should only contain Tools, so Instance:ClearAllChildren is a quick and clean method. Should you need to filter for Tools within the player’s backpack, you can take advantage of Instance:QueryDescendants to shorten your code:
local Players = game:GetService("Players")
local function clearPlayerBackpack(player: Player)
local tools = player.Backpack:QueryDescendants("> Tool")
for _, tool in tools do
tool:Destroy()
end
end
local function clearPlayerBackpacks()
for _, player in Players:GetPlayers() do
clearPlayerBackpack(player)
end
end
This was 5 years ago. I don’t think the OP or Jack care about this anymore. Pointless necrobump.
There are still other people on the internet that will take information from this post, why not complement it with better up to date information?