Dollar500
|
  |
| Joined: 12 Jan 2013 |
| Total Posts: 504 |
|
|
| 30 Apr 2016 10:54 PM |
local players = game.Players:GetPlayers()
local myTable = {}
for i, v in pairs(players) do myTable[v] = i print(myTable[v]) end
-- I am not at a computer and I'm trying to write a script. Would this just print 1, 2, 3, etc.? |
|
|
| Report Abuse |
|
|
lululukas
|
  |
| Joined: 23 Aug 2010 |
| Total Posts: 1043 |
|
|
| 30 Apr 2016 10:59 PM |
Wotdafok r u even trying to do
tab={}
for i,v in pairs(game.Players:GetChildren()) do table.insert(tab,v) end
for i,c in pairs(tab) print(i,c) end
Output:
1 Player1 2 Player2 3 Player3 4 Player4 5 Player5
etc (stops at the end of the table of players) |
|
|
| Report Abuse |
|
|
Dollar500
|
  |
| Joined: 12 Jan 2013 |
| Total Posts: 504 |
|
|
| 30 Apr 2016 11:02 PM |
| LuLuLukas, that is not what I am trying to do. I am trying to assign a number to each player. |
|
|
| Report Abuse |
|
|
Dollar500
|
  |
| Joined: 12 Jan 2013 |
| Total Posts: 504 |
|
|
| 30 Apr 2016 11:04 PM |
I want it to print this:
Player1 -> 1 Player 2 -> 2 Player3 -> 3
etc |
|
|
| Report Abuse |
|
|
lululukas
|
  |
| Joined: 23 Aug 2010 |
| Total Posts: 1043 |
|
|
| 30 Apr 2016 11:05 PM |
That's what the index numbers are for in a table
tab={player1,player2,player3}
tab[1] --same as player1 tab[2] --same as player2 tab[3] --same as player3
|
|
|
| Report Abuse |
|
|
Jammer622
|
  |
| Joined: 19 Nov 2008 |
| Total Posts: 1739 |
|
|
| 30 Apr 2016 11:13 PM |
If you want it to print it that exact way, just change print(i,c) to print(c,"->",i) wow |
|
|
| Report Abuse |
|
|
Jammer622
|
  |
| Joined: 19 Nov 2008 |
| Total Posts: 1739 |
|
|
| 30 Apr 2016 11:19 PM |
Now if you're trying to make something like
print(players[Dollar500]) -> "1"
then you want to start with an empty table and for each player in the game, assign the number to their reference name in the table
Players = {} for i, v in pairs(game.Players:GetPlayers()) do Players[v.Name] = i end print(Players[Dollar500])
you can also reference the players directly [if i recall correctly] instead of using their name in the table. i may be completely wrong on that.
Players = {} for i, v in pairs(game.Players:GetPlayers()) do Players[v] = i end print(game.Players.Dollar500) -> "1" |
|
|
| Report Abuse |
|
|
Jammer622
|
  |
| Joined: 19 Nov 2008 |
| Total Posts: 1739 |
|
|
| 30 Apr 2016 11:20 PM |
i also totally butchered that last line of the post
*print(Players[game.Players.Dollar500]) -> "1" |
|
|
| Report Abuse |
|
|
Dollar500
|
  |
| Joined: 12 Jan 2013 |
| Total Posts: 504 |
|
|
| 30 Apr 2016 11:22 PM |
Well, I think I am actually trying to do this:
local tab = {a = 1, b = 2}
I am trying to do this by inserting the values with a for loop. |
|
|
| Report Abuse |
|
|
Dollar500
|
  |
| Joined: 12 Jan 2013 |
| Total Posts: 504 |
|
|
| 30 Apr 2016 11:26 PM |
If I did this:
Players = {} for i, v in pairs(game.Players:GetPlayers()) do Players[v.Name] = 10 end print(Players[Dollar500])
Would it print 10? |
|
|
| Report Abuse |
|
|
Jammer622
|
  |
| Joined: 19 Nov 2008 |
| Total Posts: 1739 |
|
| |
|
Dollar500
|
  |
| Joined: 12 Jan 2013 |
| Total Posts: 504 |
|
| |
|