Cant get user's display name

Im trying to load any player’s user with a script, and its working fine. But when i try to laod their dislay name it doesnt work.

print(game.UserService:GetUserInfosByUserIdsAsync(game.Players:GetUserIdFromNameAsync(Username)))

The 'Username" variable is just my username. So this should print my user info, but it errors and says “cant cast array”

1 Like

Oh also, the user shouldnt have to be in the server. Thats why im doing all this extra stuff.

Try to use pcalls instead, let me know how this code works for you:

local success, userId = pcall(function() return game.Players:GetUserIdFromNameAsync(Username); end);
if success and userId then
    local success2, userInfo = pcall(function() return game.UserService:GetUserInfosByUserIdsAsync({userId}); end);
    if success2 and userInfo and #userInfo > 0 then
        print("Player's display name:", userInfo[1].DisplayName);
    else
        warn("Failed to get userid");
    end;
else
    warn("Failed to get userid");
end;
2 Likes

image
that works (i forgot i was doing flamingo, not myself)

also just a question, why are u using semicolons?

Just preference, I started in Java and C and I just like to add it.

giving me flashbacks to the arduino IDE (i hate it)

Yeah lol, it also helps me to remember that that is the end of that block of code.


(this NPC is still very early WIP) but hey its you!