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 ALL Items from the inventory? (INCLUDING THE ONE THE PLAYER HAS EQUIPPED)

I've only been able to remove the items that the player has not been holding, so I was wondering how you could do this. Thank you!

2 answers

✓ Accepted answer

To unequip any tools, use UnequipTools on the Humanoid.

To remove all items from the Backpack, run ClearAllChildren on it.

Character.Humanoid:UnequipTools()
Player.Backpack:ClearAllChildren()

In my example above, Player and Character must be defined in order for it to work as expected.

4 comments

0

I wouldn't use :ClearAllChildren() because if a script is in there it will be destroyed.

0

Why would there be a script in the Backpack, or anything other than tools?

0

Also, he said in all caps he wants to remove all items.

0

I put scripts in the backpack more than I put tools in the backpack.

Well, when the player equips a tool, it is moved to their character. The best way to do this would be to first unequip the player's tools using the :UnequipTools() method of Humanoid. The complete code is below.

function ClearTools(plr) -- plr = Player object
	plr.Character:WaitForChild("Humanoid"):UnequipTools()
	for _, v in ipairs(plr.Backpack:GetChildren()) do
		if v:IsA("BackpackItem") then -- Just incase you're using a (deprecated) HopperBin.
			v:Destroy()
		end
	end
end

I hope my answer helped! If it solved your problem please remember to mark it as correct!

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