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

Getting Backpack from Player, and removing Children?

I have been trying to figure this out for 3 days. I'm creating a minigame, and I was easily able to add the tools, but removing them has been my problem. I've manipulated this little line of code forever and just cannot figure it out, if someone can help and give me a brief explanation of my problem that would be awesome. Here's the code:

toolboxy = game.Players.Character:GetChildren()
	wait(3) 
	game.Player.Character.Backpack:ClearAllChildren() 

Like I said, I'm a Beginner's scripter, and I've tried everything possible to my ability, I tried creating a table, doing for loops, nothing. So, if someone can help I'll give you rep. Thanks!

2 answers

✓ Accepted answer
plrs = game.Players:GetChildren()
for i,v in pairs(plrs) do
v.Backpack:Destroy()
end

If you want to actually clear the Backpack instead of removing it...

plrs = game.Players:GetChildren()
for i,v in pairs(plrs) do
v.Backpack:ClearAllChildren()
end

-Thank me by accepting this answer/bumping up my reputation!

1 comment

0

Thank you, for my game I actually do have to clear the Backpack, so. Rep + Accept

You need to remove everything from the Backpack and check for equipped tools in the player's character. You also have to loop through character to access items, you can't just say :GetChildren(), that just makes a table.

for i,v in pairs(game.Players:GetPlayers()) do 
	for a,b in pairs(v.Character:GetChildren()) do 
		if b:IsA("Tool") or b:IsA("HopperBin") then 
			b:Destroy()
		end
	end
	v.Backpack:ClearAllChildren()
end

IsA()

for index,variable in pairs

1 comment

0

Thanks, I'm accepting your answer for detail, but both of you are getting rep for helping out.

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