Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

Insert Player Names Into A Table?

Asked by 9 years ago
local players = {""}

game.Players.PlayerAdded:connect(function(player)
local getPlayerNames = game.Players:GetPlayers().Name
table.insert(players, getPlayerNames)
wait(0.1)
print(table.concat(players, ", ")
end)

I am trying to make a table that holds the value of all of the player's names in the server, but the above code doesn't work. Can someone help me out?

1
Line 4 is not necessary, all you need to do is change line 5 [table.insert(players,player.Name)]. TheeDeathCaster 2368 — 9y
0
ok thanks alienantics 15 — 9y

1 answer

Log in to vote
0
Answered by 9 years ago

First off, let's address the issues:

  • You attempt to get the name of a table.
  • On line 1, you create the table with a string already in it, this will cause problems with your concatenation.

Let's fix those problems now.

local players = {};

game.Players.PlayerAdded:connect(function(player)
table.insert(players, player.Name);
wait(0.1);
print(table.concat(players, ", ");
end);

NOTE: The wiki is a great place to research anything you don't understand

Ad

Answer this question