Hello, I am making a players table so I can easily access players, but here is my problem:
1 | local playersTable = { } |
2 |
3 | game.Players.PlayerAdded:Connect( function (player) |
4 | table.insert(playersTable, table.getn(playersTable) + 1 , player) |
5 | end ) |
6 | print (playersTable) |
Once I run this script I get this in the output: table: 0x51474be0bb02eb5c I probably shouldn't use table.getn I'm guessing? If not then what could I use? Sorry if this question is easy, but I look over the developer hub and couldn't find anything
You are getting the "strange" output because you are outputting the table itself and not the contents of the table. A simple for loop can fix that:
1 | for i,v in pairs (playersTable) do |
2 | print (v) -- v would be the entry and i is the index (position in the table) |
3 | end |
Additionally to get the amount of entries in a table just do #playersTable. In this specific use case you wouldn't need to even specify the index number since new table entries will always default to #table + 1 (which is what you are doing)