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

Printing names with table.insert?

I have NEVER used table.insert but trying to learn it. I am trying to print all players in the game, I get no error.

local Players = {}
for i, v in pairs(game.Players:GetPlayers()) do
    if v.Character then
         table.insert(Players, v.Name)
			print(Players)
    end
end

1 answer

✓ Accepted answer

Players is a table, not a player. So when you print it, you'll get something like this: table: 1A1D9D00

You actually don't need the extra table at all.

for i, v in pairs(game.Players:GetPlayers()) do
	if v.Character then
		print(v)
	end
end

But wait! This doesn't help, because you're trying to learn about table.insert. So let's fix your original code, even though that's not something you'd want to do in a real situation.

local Players = {}
for i, v in pairs(game.Players:GetPlayers()) do
	if v.Character then
		table.insert(Players, v.Name)
	end
end
--Now all the players should be in the Players table
for i, v in pairs(Players) do
	print(v)
end

2 comments

0

Did not print.

0

If it's running as soon as the game starts, it will run before anyone joins, therefore not printing. Just delay it a bit.

This discussion is preserved as it was. New answers, comments, and votes are closed.