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

does "for _,plr in pairs(game.Players:GetPlayers()) do end" Really get players in pairs?

So, For I while i have used

for _,plr in pairs(game.Players:GetPlayers()) do
        
    end

to change something for everyplayer through a normal script.

But does this code actually affect players in pairs?

If so, how can i loop through each player individually?

Thanks in advance for looking at my quesiton.

2 comments

0

It's better to use ipairs in your case.

1 answer

✓ Accepted answer

All pairs means is that it continuously gives you both the key and the value. That's the pair. No, players are not dealt with in pairs.

If so, how can i loop through each player individually?

You already do. To see it more clearly you can use the for-loop equivalent. Pairs is actually only super useful for dictionaries. But it is often used because it skips a few lines.

local array = game.Players:GetPlayers()
for i=1,#array do
	local v = array[i]
	--code
end

For more information:

http://wiki.roblox.com/index.php?title=Generic_for

1 comment

0

Thank You for clarifying this for me

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