Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
1

Getting Backpack from Player, and removing Children?

Asked by
bloxxyz 274 Moderation Voter
10 years ago

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

Log in to vote
1
Answered by
Shawnyg 4330 Trusted Badge of Merit Snack Break Moderation Voter Community Moderator
10 years ago
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!

0
Thank you, for my game I actually do have to clear the Backpack, so. Rep + Accept bloxxyz 274 — 10y
Ad
Log in to vote
2
Answered by
Azarth 3141 Moderation Voter Community Moderator
10 years ago

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

0
Thanks, I'm accepting your answer for detail, but both of you are getting rep for helping out. bloxxyz 274 — 10y

Answer this question