Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

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

Asked by
TD0707 0
2 years ago
Edited 2 years ago
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

Log in to vote
1
Answered by 2 years ago

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

0
Why not just do ":ClearAllChildren()"? You shouldn't really store anything other than tools in the backpack anyway, Great answer nonetheless. PastDays 108 — 2y
0
True, thanks though AidanTES 36 — 2y
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. TD0707 0 — 2y
0
I tried your script and the items reappear in your Backpack when you respawn. TD0707 0 — 2y
Ad

Answer this question