I want to create something inside of a table when a function is triggered, I also don't know it's index number. How can I get Roblox to print the newly added thing in the table?
1 | local Players = game.Players |
2 |
3 | PlayerList = { } |
4 |
5 | Players.PlayerAdded:Connect( function (player) |
6 | table.insert(PlayerList, 1 ,player.name) |
7 | end ) |
8 |
9 | print (PlayerList [ 1 ] ) --- I don't know the index number. |
I mainly want to know how to print the index number, any other mistake is most likely a typo (If not please point it out).
1 | local Players = game:GetService( "Players" ) |
2 |
3 | PlayerList = { } |
4 |
5 | Players.PlayerAdded:Connect( function (player) |
6 | PlayerList [ #PlayerList + 1 ] = player.Name -- Replacing the Table Indexs Total plus 1 to the player.Name, in that way, table with 0 index plus 1 will be 1, and it replaces the 1st table position to the player.Name. |
7 | print (PlayerList [ #PlayerList .. " joined the game." ] ) -- Get the total index in PlayerList, if there is 1 index, it prints the first index. |
8 | end ) |