Way to get UserInfoByUsername?

I want to get user information through the username. I am making a game where you can enter a players username and it will show the information of the player. (ID, Display Name, Username, Profile)

I know you can use UserService to get the username, display name, and the ID with UserService:GetUserInfosByUserIdsAsync()
But I am trying to find a way to get players information with the username, not ID and I havent found anything online.

Thanks!

Do you need the Id or the Name? If you need the id by the Name you can use game.Players:GetUserIdFromNameAsync(Player.Name); this method errors if no account exists with the given username. If you aren’t certain such an account exists, it’s recommended to wrap calls to this function with a pcall.

Yes, i believe thats how it works, but do you mean?

game.Players:GetNameFromUserIdAsync()?

Dependinding on what they need for that reason I specified:), and good night! to all.

Hi!

so um, i made this script, and it seems to get the Players Name and UserId just fine.

Use a TextBox and put this code in a LocalScript and Parent it to the TextBox.

script.Parent.InputEnded:Connect(function()
local Success, Errors =  pcall(function()

	local AB = script.Parent.Text
	if AB then
		local A = game.Players:GetUserIdFromNameAsync(AB) or nil
			local B = game.Players:GetNameFromUserIdAsync(A)
			
		if A ~= nil then
				print("Player Found: "..B)
				print("UserId: "..A)
				
		else
			print("Not A Player")
		end
	end
	end)
if Success then
	print("Finished")
else
	warn("Failed to Grab Player Stats:  "..Errors)
end	
end)

local userService = game:GetService("UserService")

local name = "Searched Player"
	
local userId = game.Players:GetUserIdFromNameAsync(name)
	
userService:GetUserInfosByUserIdsAsync({userId})

I checked the code:

Got this as a result:

23:20:51.339  {}  -  Client - B:35
 23:20:51.646  {}  -  Client - B:35

Its at line 35 cus i covered the other code with a comment

Yeah you didnt printed the Result, wait

can you specify? ive been checking the code and getting the same result. Doesnt seem to work

this is the code i tried for the Textbox, Its modified so it doesnt print blank:

script.Parent.InputEnded:Connect(function()
local US = game:GetService("UserService")

	local Text = script.Parent.Text
	if Text then
local UserId = game.Players:GetUserIdFromNameAsync(Text)
if UserId ~= nil then
			local data = US:GetUserInfosByUserIdsAsync({UserId})
			if UserId ~= nil and not "{}" then
wait(5)
				print(data)
			end
		end
		end
	end)

the code checks the text the player has entered and see’s if its a Players Name
(im not the OP)

1 Like
local userService = game:GetService("UserService")

local name = "Your Name"

local userId = game.Players:GetUserIdFromNameAsync(name)

local successOrNot, result = pcall(function()
	return userService:GetUserInfosByUserIdsAsync({userId})
end)

if successOrNot == true then
	for user, userInfos in ipairs(result) do
		print("Your UserId = "..userInfos.Id)
		print("Your Username = "..userInfos.Username)
		print("Your DisplayName = "..userInfos.DisplayName)
	end
end

or if you want to use PlayerAdded:

game.Players.PlayerAdded:Connect(function(player)

local userService = game:GetService("UserService")

local successOrNot, result = pcall(function()
	return userService:GetUserInfosByUserIdsAsync({player.UserId})
end)

if successOrNot == true then
	for user, userInfos in ipairs(result) do
		print("Your UserId = "..userInfos.Id)
		print("Your Username = "..userInfos.Username)
		print("Your DisplayName = "..userInfos.DisplayName)
	end
end

end)

Thanks for clarifying, the other posts didnt really show much

1 Like

No problem, did it worked also for u?


No Response from the Script or Output.

The Script Works, but however there is one flaw, the script doesnt check moderated users.

This Script seems better at doing that.

What do u mean with moderated Users

When you look up a user who is banned or terminated, you dont get a result, however with my script, you do get results, The Full Username and UserId

Small Example:


the script aint perfect but it gets the job done, ill see what i can do for DisplayName
Edit: some of these users arent terminated but you get the point.

make sure code is in StarterGui to run.
Script Code rn:

script.Parent.InputEnded:Connect(function()
local Success, Result =  pcall(function()

	local AB = script.Parent.Text
	if AB then
		local A = game.Players:GetUserIdFromNameAsync(AB) or nil
			local B = game.Players:GetNameFromUserIdAsync(A)
			local T = game.Players:GetUserThumbnailAsync(A, Enum.ThumbnailType.HeadShot, Enum.ThumbnailSize.Size420x420)
			local T2 = game.Players:GetUserThumbnailAsync(A, Enum.ThumbnailType.AvatarThumbnail, Enum.ThumbnailSize.Size420x420)
			
		if A ~= nil then
				print("Player Found: "..B)
				print("UserId: "..A)
				script.Parent.Parent.FullName.Text = B
				script.Parent.Parent.UserId.Text = A
				script.Parent.Parent.Image.Image = T
				script.Parent.Parent.Image2.Image = T2
				workspace.Audio.UI.Award:Play() -- Not Important, just a sound i added.
				
		else
			warn("Found nil")
		end
	end
	end)
if Success then
		print("Finished")
		
else
	warn("Failed to Grab Player Stats:  "..Result)
end	
end)

ill update it.

If you want the display name (and various other information) you must use UserService and the function GetUserInfosByUserIdsAsync.

You mean UserService; ProfileService is an open source module

2 Likes

Sure, and sorry I’m from my cellphone answering.

I did that, it works but the only issue i found is that you cant look find moderated users.