I am trying to make it so I can get the player’s displayname from their UserId. I have found out that I can use Players:getUserInfosFromUserIdsAsync() to get the DisplayName but when I try to do that it comes up with an error from the pcall.
GetUserInfosByUserIdsAsync is not a valid member of Players "Players" - Client
I can’t figure out how I am suppose to do this. Can’t you use this function anymore?
Here is my code:
local userInfo
local success, errormessage = pcall(function()
userInfo = game.Players:GetUserInfosByUserIdsAsync({userID})
end
if success then
print(userInfo.Username)
print(userInfo.DisplayName)
playerInfoFrame:WaitForChild("DisplayName").Text = userInfo.DisplayName
playerInfoFrame:WaitForChild("Username").Text = userInfo.Username
else
warn(errormessage)
end
If you can’t use GetUserInfosByUserIdsAsync() anymore, is there an alternative?
The problem here is that you’ve said game.Players, when looking at the devhub of this function it is under the service “UserService” so try
local UserService = game:GetService("UserService")
UserService:GetUserInfosByUserIdsAsync({userID})
Edit: Just realised there is a couple more errors
You need to define newPlayerPage and the userId
local player = game.Players.LocalPlayer
local playerInfoFrame = player.PlayerGui.newPlayerPage:WaitForChild("playerInfo")
local UserService = game:GetService("UserService")
local success, result = pcall(function()
return UserService:GetUserInfosByUserIdsAsync({80000})
end)
if success then
for _, userInfo in ipairs(result) do
print("Id:", userInfo.Id)
print("Username:", userInfo.Username)
print("DisplayName:", userInfo.DisplayName)
playerInfoFrame:WaitForChild("DisplayName").Text = userInfo.DisplayName
playerInfoFrame:WaitForChild("Username").Text = userInfo.Username
end
else
warn(result)
end
I have experienced and fixed this issue a while back ago when I was making a resource.
Use this:
local ID = --UserID
local UserService = game:GetService("UserService")
local success, Info
success, Info = pcall(function()
return UserService:GetUserInfosByUserIdsAsync({ID})
end)
local DisplayName = Info[1].DisplayName
--aditional
print(CreatorDisplayName) --DisplayName, if any
This should work for players that are not in the game. If not, you will need to use a proxy. I haven’t tested it outside.
Ah, okay. It’s just weird because on the developer website it said Players in the code and thought it was in game.Players. It said Function of UserService, but I didn’t see that.
Thanks.