Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
✓ ANSWER ACCEPTED

Why wouldn't my table would print the players?

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

2 comments

0

Do you want it to print ALL of the players?

0

Try table.insert(plrs,#plrs + 1, player)

2 answers

✓ Accepted answer

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

2 comments

0

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.

0

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.