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

How do you remove everything in a player's backpack?

So this is my script this is a rebirth now if you see in the code theres a child:remove() When i tested it it doesnt remove the child like how plz help im a nub at scripting :)

local replicatedStorage = game:GetService("ReplicatedStorage")
local StarterRebirthAmount = 60000
local player = game.Players.LocalPlayer
local mainframe = script.Parent:WaitForChild("MainFrame")
local rebirthMenu = mainframe:WaitForChild("Frame")
local mainbutton = script.Parent.MainButton
local rebirthbutton = rebirthMenu:WaitForChild("Rebirth")
local stregthnToRebirth = rebirthMenu:WaitForChild("Strenght")
local rebirths = player:WaitForChild("leaderstats").Rebirth

wait()
stregthnToRebirth.Text = "You need atleast "..math.floor((StarterRebirthAmount + (rebirths.Value) * math.sqrt(50000000))).." balloons to rebirth"

mainbutton.MouseButton1Click:Connect(function()
	mainframe.Visible = not mainframe.Visible
end)

rebirthbutton.MouseButton1Click:connect(function()
	local result = replicatedStorage.Remotes.Rebirth:InvokeServer()
	
	if result == true then

		if result == true then
				
		local children = player.Backpack:GetChildren()
		
		for i = 1, #children do
			local child = children[i]
			child:Remove()
		end


		rebirthbutton.Text = "succesfully rebirthed"
		wait(1)
		rebirthbutton.Text = "Click here to rebirth"
		
		
	elseif result == "NotEnoughBalloons" then
		rebirthbutton.Text = "Pro Tip:Grind More"
		wait(2)
		rebirthbutton.Text = "Click here to rebirth"
		end
	end
end)

rebirths:GetPropertyChangedSignal("Value"):Connect(function()
	stregthnToRebirth.Text = "You need atleast "..math.floor((StarterRebirthAmount + (rebirths.Value) * math.sqrt(50000000))).." balloons to rebirth"
end)

All of you have a great night or day,God bless u

1 answer

✓ Accepted answer

add in this:

player.Backpack:ClearAllChildren()

for _,v in pairs(player.Character:GetChildren()) do
	if v:IsA("Tool") then
		v:Destroy()
	end
end)

The first line clears the backpack/inventory Anything following that will work to clear what's in the player's hand. Just make sure that player = the player you want to clear. You can add this anywhere to clear the inventory.

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