|
| 12 Mar 2016 10:15 PM |
Hello, I'm fairly new to tables. Anyone know how to gather all players and put them in a table? Please help!
|
|
|
| Report Abuse |
|
|
malachi11
|
  |
| Joined: 07 May 2008 |
| Total Posts: 2420 |
|
|
| 12 Mar 2016 10:16 PM |
game.Players:getChildren()
That returns a table of all the children in Players. |
|
|
| Report Abuse |
|
|
|
| 12 Mar 2016 10:17 PM |
There's a convenient method for that, game.Players:GetPlayers()
It'll give you the table of every Player within game.Players.
You can use :GetChildren() to do the same with any other object
https://youtu.be/L78yVFeyvRo?t=31 |
|
|
| Report Abuse |
|
|
|
| 12 Mar 2016 10:18 PM |
Thank you all, but I would want insert them into a table. Like table.insert?
|
|
|
| Report Abuse |
|
|
malachi11
|
  |
| Joined: 07 May 2008 |
| Total Posts: 2420 |
|
|
| 12 Mar 2016 10:19 PM |
| GetChildren() or GetPlayers() already returns a table. You don't need to insert them into one. |
|
|
| Report Abuse |
|
|
|
| 12 Mar 2016 10:21 PM |
Okay. Thanks! I want to make a game with "rounds". And whenever someone dies, it takes their name out of the table. Can I do that with GetChildren()?
|
|
|
| Report Abuse |
|
|
|
| 12 Mar 2016 10:22 PM |
^ getChildren is deprecated, GetChildren should be used instead.
Also, GetChildren returns all objects, not just players. For this purpose, GetPlayers should be used. |
|
|
| Report Abuse |
|
|
|
| 12 Mar 2016 10:39 PM |
It returns a table, so you can do everything you normally would with it When a player dies, find them in the table and you can run table.remove() on it to remove them from your table |
|
|
| Report Abuse |
|
|
|
| 12 Mar 2016 10:40 PM |
How can I set it as a variable?
|
|
|
| Report Abuse |
|
|
|
| 12 Mar 2016 10:41 PM |
The same way you set any other variables:
local players = game.Players:GetPlayers() |
|
|
| Report Abuse |
|
|