Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
COMMUNITY QUESTION

How can I remove all gears from your StarterGear in Players when you click a button?

local Player = game.Players.LocalPlayer
local Button = script.Parent

Button.MouseButton1Click:Connect(function()
	Player.Backpack:ClearAllChildren()
	Player.StarterGear:ClearAllChildren()
end)

I am able to clear Backpack and StarterGear, but when you respawn the items reappear in your inventory. I believe it is because it saves in your StarterGear but I may be incorrect.

1 answer

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

0

Why not just do ":ClearAllChildren()"? You shouldn't really store anything other than tools in the backpack anyway, Great answer nonetheless.

0

True, thanks though

0

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.

0

I tried your script and the items reappear in your Backpack when you respawn.

This discussion is preserved as it was. New answers, comments, and votes are closed.