How to get a player by username on the server

Hello i’m trying to make a game where you can look up information on players. I’m having an issue with the find users script as i cant figure out how to find a user by there username
thats not in the current game.

i understand players:GetUserIdFromNameAsync() but how do i do it for players not in the game

2 Likes

Find first child is an okay way for that, but problem comes when there is more than one of same named player in same server.

1 Like

im not asking about players that are in the same game

game.Players works for players that are not in the game aswell.

You could get someone’s ID from it , even if they arent in your game. Same for their username.

For displayname, you’d have to use a proxy.

Try to run this command in a script:

print(game:GetService("Players"):GetUserIdFromNameAsync("Roblox"))

Edited

1 Like

what do you mean i would have to use a proxy?

how would i tell if theres no player with that name? like they spammed text or they said there username wrong

Simply check if this condition could be found

if game:GetService("Players"):GetUserIdFromNameAsync("Roblox") then
end

(I suggest using pcalls )

local success,Result = pcall(function()
    return game:GetService("Players"):GetUserIdFromNameAsync("Roblox")
end)

if success then
   print(result)
end
2 Likes

Yes i was just about to say that i noticed it sent an error when it was a invalid user and to use pcall.

i did this which works:

local success,failure = pcall(function()
			game:GetService("Players"):GetUserIdFromNameAsync(script.Parent.Parent.User.Text) 
		end)
		if not success then
			script.Parent.Parent.FindUser.Text = "Invalid User"
		else
			script.Parent.Parent.FindUser.Text = "Get Info"
		end

thanks for the help

1 Like