If my answer helped, please approve it!~
Initialize the variables,
local Player = game.Players.LocalPlayer
local Button = script.Parent
Put in the function,
Button.MouseButton1Click:Connect(function()
end)
Loop through all the items in their backpack
for _, Tool in pairs(Player.Backpack:GetChildren()) do
if Tool:IsA("Tool") then
Tool:Destroy()
end
end
Do the same for their StarterGear
for _, Tool in pairs(Player.StarterGear:GetChildren()) do
if Tool:IsA("Tool") then
Tool:Destroy()
end
end
All together should be:
local Player = game.Players.LocalPlayer
local Button = script.Parent
Button.MouseButton1Click:Connect(function()
for _, Tool in pairs(Player.Backpack:GetChildren()) do
if Tool:IsA("Tool") then
Tool:Destroy()
end
end
for _, Tool in pairs(Player.StarterGear:GetChildren()) do
if Tool:IsA("Tool") then
Tool:Destroy()
end
end
end)
If I messed something up let me know because I'm very prone to that :P
4 comments
Why not just do ":ClearAllChildren()"? You shouldn't really store anything other than tools in the backpack anyway, Great answer nonetheless.
True, thanks though
I'm making a clear inventory button so you can unequipped items that you don't want anymore. There are 12 different items in the game that are able to be equipped so it would be hard to specify each individual item.
I tried your script and the items reappear in your Backpack when you respawn.