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

Backpack Script equals to false?

Asked by 10 years ago

I have a backpack script. It's suppose to make everything in the backpack be removed.

game.Workspace.Players.Username.Backpack:remove()

The script returns to false. Why so?

3 answers

Log in to vote
1
Answered by 10 years ago

You do not want to remove the backpack itself, just the children in it.

for i,v in pairs(game.Workspace.Players.Username.Backpack:GetChildren()) do v:Destroy() end
0
You could simplify this by just use the ClearAllChildren method. User#11893 186 — 10y
0
@Kenetec You are right. Thank you. User#2263 0 — 10y
Ad
Log in to vote
2
Answered by 10 years ago

Fixed your errors:

game.Players.PlayerNameHere.Backpack:ClearAllChildren()

But change PlayerNameHere to the players username

Log in to vote
0
Answered by 10 years ago

You tried to remove the backpack. Instead, remove its children.

children = game.Workspace.Players.Username.Backpack:GetChildren()
for k, child in pairs(children) do
    if child:IsA('Part') and not child.Locked then
        child:Destroy()
    end
end

Should be something like that. If it doesn't work, sorry about that. I got it off the wiki and modified it slightly.

Answer this question