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

Help with :GetPlayers for loop?

for _,players in pairs(game.Players:GetPlayers())
	for i = 1, #players do
		print(""..player.Name..""..i.."")
	end
end

I want this to get all the players names and then print them so it would look like this: NinjoOnline 1 rarchet 2 daaabosss 3 So that way it gets each players name and gives them a select number after that, so I can do lists, etc. Anyone know whats wrong. Their is nothing in the output, so I don't know what the problem is.

NinjoOnline

3 comments

0

NinjoOnline logic: Asks question, downvotes 2 good answers

0

Thats cause both them don't work, ah doi, I would vote up if you had an answer that would work. And so you downvote for giving you a downvote, thats not what this site was, retaliation?

0

and there second answer isnt good, it has multiple things missing, first of all it wont work like that, it needs a do, so I have to -1 as the script MUST be 100% ACCURATE, and must work.

2 answers

✓ Accepted answer

On line 1, "players" is the player item itself. So, line 2 with "for i = 1, #players do" will not work. Here's the fixed version:

for i, player in pairs(game.Players:GetChildren()) do
print(player.Name.." "..i) --the quotes in there are for a space, you can remove them if you want
end

4 comments

0

no such thing as game.Players:children() Please answer it 100% exact.

0

Yes there is. It gets the children of the Players service.

0

its called GetChildren() dooii

0

:Children() still works. It's deprecated, but still works.

num = 0
for _,players in ipairs(game.Players:GetPlayers())
	num = num + 1
	print(player.Name.." "..num = 0)
end

3 comments

1

Explain what you changed.

0

forgot the do in the for loop

1

in fact a few things are wrong, 1 the do in the for loop, 2 in print you said player.Name, when player is never specified, and 3 num = 0 is invalid.

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