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

How to remove everything in the players backpack?

I want to make it so that it will remove all the things in a players backpack. Not really sure how to do it though.

for i,v in pairs(game.Players:GetPlayers()) do
			w = v.Backpack:GetChildren()
			for i = 1,#w do
			w[i]:remove()
			end
		end

It also looks like it only removes one of the items if that helps. Thanks

2 comments

0

First, remove is depreciated. Destroy is preferred. That could be your problem, because I can't see anything else wrong.

0

Depracated functions are not a problem. I just returned to Roblox after a lengthy absence, during which remove was deprecated, and I've been using it as I normally would with no issues.

2 answers

I don't see anything wrong with yours. It is removing all tools/hopperbins in everyones backpack though.. Try this.

for i,v in pairs(game.Players:GetChildren()) do --Get all children of players
	Backpack = v:FindFirstChild("Backpack",true)
	if Backpack ~= nil then  --Check if the child has a backpack
		c = Backpack:GetChildren() --Get the children of the backpack
		for i = 1,#c do
			c[i]:Destroy() --Use Destroy method instead
		end
	end
end)

Again, I don't know what was wrong with yours but I hope this fixes it.

Hope I Helped

+1

A better way to do this:

for _,v in pairs(game.Players:GetPlayers()) do
	v.Backpack:ClearAllChildren() 
end

ClearAllChildren

1 comment

0

I somehow wandered into this code, thanks for it! I needed it for my criminal laser kill for my jail game!

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