How do I clear all tools from your Backpack and startergui with a gui button?

I have a question about the starter pack.
How can I clear the starter pack and the backpack with a GUI button?

I have tried many things so far. And I still don’t know what to do.

If you have any feedback please let me know.

Thank you!

local LOCAL_PLAYER = game:GetService("Players").LocalPlayer

local Gui = LOCAL_PLAYER.PlayerGui:WaitForChild("ScreenGui")

Gui.TextButton.MouseButton1Click:Connect(function()
	for i,v in pairs(LOCAL_PLAYER.Backpack:GetChildren()) do
		if v:IsA("Tool") then
			v:Destroy()
		end
	end
end)

Thanks! But do you know if there is a way to clear the players selected tools aswell?

if your script is a localscript, which it is because it is inside a gui button, you can just loop through the backpack and check if the object is a tool and then Destroy it or store it, using the generic for loop, also we have to check the character because the equipped tools are in the character itself, so you can just put a script and do the button1Click event, also get the localplayer

local player = game.Players.LocalPlayer

yourbuttonhere.MouseButton1Up:Connect(function()
    local backpack = player:WaitForChild("Backpack") -- Because the backpack doesn't load right away, we have to wait for it  
    for _, tool in pairs(backpack:GetChildren()) do -- I put it as "tool" to make it easier to reference
       if tool:IsA("Tool") then
           tool:Destroy()
           -- tool.Parent = game.ReplicatedStorage
           -- that is for if you want to store the tool
       end
    end
end)

next thing you have to do is check the character because the equipped tools will be in the character itself, so just do the same thing but do player.Character instead of backpack like so:

local player = game.Players.LocalPlayer

yourbuttonhere.MouseButton1Up:Connect(function()
    for _, tool in pairs(player.Character:GetChildren()) do
       if tool:IsA("Tool") then
           tool:Destroy()
           -- tool.Parent = game.ReplicatedStorage
           -- same thing for if you want to store the tool
       end
    end
end)

and that is all
(also sorry if you don’t understand, I’m bad at explaining)

1 Like

Omg that worked!! Thank you so much!