Im trying to make this script print the names of all players in the game please help!
1 | for i, v in pairs (game.Players:GetPlayers()) do |
2 | print (i) ---player priority |
3 | print (v) ---players name |
4 | end |
1 | game:GetService( "Players" ).PlayerAdded:Connect( function () |
2 | for i,v in pairs (game:GetService( "Players" ):GetPlayers()) do |
3 | print (v.Name) |
4 | end |
5 | end ) |
when someone joins the game you make a loop through all the players and print their names
Instead of using an in pairs loop, I would print them in a table so it's easier to read. Here
01 | local playerService = game:GetService( "Players" ) |
02 | local playerTable = { } |
03 |
04 | game.Players.PlayerAdded:Connect( function (player) |
05 | table.insert(playerTable [ player.Name ] ) |
06 | end |
07 |
08 | game.Players.PlayerRemoved:Connect( function (player) |
09 | table.remove(playerTable [ player.Name ] ) |
10 | end |
11 |
12 | while wait( 15 ) do |
13 | print ( "playerTable" ) |
14 | end |