How to get all players UserIds

Hello, I was wondering how I would go about getting all the players in the server UserIds!

1 Like

Simply loop through the players and add their UserId to a table.

local userIds = {}

for _, player in pairs(game.Players:GetPlayers()) do
table.insert(userIds, player.UserId)
end

print(userIds)
5 Likes

Alright, for this, let’s preform a loop to get all the player’s userId’s. We can do so by using the getPlayers() method.

local PlayerIDTable = {} -- Get a table to store all the ID's.
local allPlayers = game.Players:GetPlayers() -- Get our path to the players.
for i = 1, allPlayers[i] do
    table.insert(PlayerIDTable, allPlayers[I].UserId)
end
print(PlayerIDTable) -- Let's see all the player's ID's...

(Not the best code. e.e)

3 Likes