How to get a list of players by searching for name

I want to get a list of players by searching the name like the roblox website does for my admin panel but i dont know how to do it, does anyone know? i only know how to get userid from a name but thats not really a search

To do so, you will want to make an HTTP request to the https://users.roblox.com/v1/usernames/users endpoint.

Example as a curl:

curl -X POST https://users.roblox.com/v1/usernames/users \
  -H "Content-Type: application/json" \
  -d '{"usernames": ["creaco"], "excludeBannedUsers": false}'

Example in ROBLOX:

local HttpService = game:GetService("HttpService")

local url = "https://users.roproxy.com/v1/usernames/users"
local bodyTable = {
    usernames = { "creaco" },
    excludeBannedUsers = false
}
local bodyJson = HttpService:JSONEncode(bodyTable)

local success, result = pcall(function()
    return HttpService:PostAsync(
        url,
        bodyJson,
        Enum.HttpContentType.ApplicationJson
    )
end)

print(result)

Alternatively, you can GET using “https://users.roproxy.com/v1/users/search?keyword=username&limit=10” (And you can increase the limit if needed) Which allows you to get multiple accounts with similar names

2 Likes

In what space are you searching? Your own admin panel data? The Roblox data/all Roblox players?

In general the algorithm for returning N amount of players is the following:

  1. Sort the table of all the players in your search in ascending order(you only need to do this once, if you need to insert a new player to the sorted table, just do binary search to figure out the index to place them into).
  2. Perform binary search to find the index of the first player whose username starts with your desired prefix/search term
  3. Return that player, and also the players after that index, until either the prefix stops matching, or you reach the amount N.
1 Like