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

Help with :GetPlayers for loop?

Asked by 9 years ago
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

0
NinjoOnline logic: Asks question, downvotes 2 good answers bobafett3544 198 — 9y
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? NinjoOnline 1146 — 9y
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. NinjoOnline 1146 — 9y

2 answers

Log in to vote
0
Answered by 9 years ago

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
0
no such thing as game.Players:children() Please answer it 100% exact. NinjoOnline 1146 — 9y
0
Yes there is. It gets the children of the Players service. bobafett3544 198 — 9y
0
its called GetChildren() dooii NinjoOnline 1146 — 9y
0
:Children() still works. It's deprecated, but still works. bobafett3544 198 — 9y
Ad
Log in to vote
-1
Answered by 9 years ago
num = 0
for _,players in ipairs(game.Players:GetPlayers())
    num = num + 1
    print(player.Name.." "..num = 0)
end
1
Explain what you changed. M39a9am3R 3210 — 9y
0
forgot the do in the for loop NinjoOnline 1146 — 9y
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. NinjoOnline 1146 — 9y

Answer this question