Get a list of players with a display name

How would I get a list of players with a certain display name, then get their username or userid, and put them in a table.

Something like this may work

local Players = game:GetService("Players")

local Name = "" -- Put the name here
local UsersWithName = {}

for i, Player in ipairs(Players:GetPlayers()) do
	if Player.DisplayName == Name then
		table.insert(UsersWithName, Player.UserId)
	end
end
2 Likes

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.