Here's a fixed version of your script:
for _, player in pairs(game.Players:GetPlayers()) do
for _, child in pairs(player:GetChildren()) do
child:Destroy()
end
end
Here's what changed.
First, we changed the top line, which was:
for i,v in pairs(game.Players:GetPlayers()) do
to this:
for _, player in pairs(game.Players:GetPlayers()) do
The only real difference here is the naming scheme. Calling a variable _ is the common practice for a variable that you don't use in Lua. We also name the second variable player, since that's the player object we're dealing with.
Next, we changed this:
children = v.Backpack:GetChildren()
children:remove()
to this:
for _, child in pairs(player:GetChildren()) do
child:Destroy()
end
First of all, you can't call methods on the result of GetChildren, since GetChildren returns a table of objects. A table of objects doesn't have regular ROBLOX methods, so we have to iterate through it and perform actions on each one using another for loop.
Another key thing to note is how we use Destroy instead of remove in the modified version. remove is a deprecated method that has garbage collection issues. (don't worry if you don't know what garbage collection means)
I hope this helps you out. Good luck!
7 comments
both of you got this wrong. its :Destroy() not :remove()
There now it is Destroy lol.
I wouldn't use ClearAllChildren. It uses :remove(), so I'm not sure why it isn't deprecated already.
:remove() works and I use it all the time.
It just sets the parent to nil, it doesn't destroy the object like destroy does.
Let me reword that sentence, lol. I knew that I just worded it wrong
It works. Thank you very much. Knew I missed a step heh. Noice.