I want to print players but it wouldn't print the players
local plrs = {}
for i,player in pairs(game.Players:GetPlayers()) do
table.insert(plrs,player)
wait(2)
print(plrs[1])
end
####Re - edited by JesseSong
I want to print players but it wouldn't print the players
local plrs = {}
for i,player in pairs(game.Players:GetPlayers()) do
table.insert(plrs,player)
wait(2)
print(plrs[1])
end
####Re - edited by JesseSong
All you simply have to do is add a player event like so.
local player = game:GetService("Players").PlayerAdded:Connect(function(player)
local plrs = {}
for i,player in pairs(game.Players:GetPlayers()) do
table.insert(plrs,player)
wait(2)
print(plrs[1])
end
end)
If you need anymore assistance please comment.
First mistake is that you need to get the Name property of the player. Second is that you were calling the first index every time, so it would've only printed the first person added to the table. Hope this helps.
local plrs = {};
for i, plr in pairs(game.Players:GetPlayers()) do
table.insert(plrs, plr);
print(plrs[#plrs].Name);
wait(2);
end
The code you provided will not run, because there isn't any player event. You also don't need semi-colons when working with this task.
Printing the player and not the .Name property of the player would still work alternatively.
This discussion is preserved as it was. New answers, comments, and votes are closed.
2 comments
Do you want it to print ALL of the players?
Try table.insert(plrs,#plrs + 1, player)