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.
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.
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})
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)
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)
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)