Getting the display name from UserId?

Hey developers, quick question…

How can I get a player’s display name from their userid?
I couldnt find anything on Roblox Creator Documentation but if anyone knows it’s you guys.

Something like Players:GetNameFromUserIdAsync() but display names - if this doesnt exist it should.
I’m too lazy to have to use https://api.roblox.com/docs?useconsolidatedpage=true smhmshmsmh.

Thanks!

2 Likes

Yes this is possible by using UserService | Roblox Creator Documentation

13 Likes

Seems difficult compared to getting the username. Thanks!

1 Like

It is way easier if you just use:

local displayName = game.Players.LocalPlayer.DisplayName

This way you don’t have to go through all that arrays and table. :slight_smile: You can change the solution if you like :wink:

1 Like

This doesn’t work if the player isn’t in the game, which is the purpose of the UserService::GetUserInfosByUserIdsAsync API.

6 Likes

UserService::GetUserInfosByUserIdsAsync
returns both username & userId, so you only have to call that method.

1 Like

Yes, but the reason to get the display name of a player while they are not in game is pretty slim

That’s actually not the case, otherwise they would have never introduced this API

2 Likes

That’s the reason I created this topic! I was making a global donation board and I needed to get the display name of players that aren’t in the game.

Thanks for the contributions both @AlreadyPro and @John_15051 but this is a solved thread and it doesn’t really warrant further replies.

@AlreadyPro: What I meant by “Seems difficult compared to getting the username.” was that with username you can just do GetNameFromUserIdAsync and I assumed they did the same with DisplayName, not have to get it through some rando dictionary.

3 Likes

Yeah, I agree. It’s also weird that GetUserInfosByUserIds is under a whole different service. There’s also no way to get DisplayName directly from a username. In my case, where I’m only given a username, this means I have to make two different web calls (GetUserIdFromNameAsync & GetUserInfosByUserIdsAsync) just to get the DisplayName.

4 Likes

That’s exactly what I have to do as well, cause the Datastore is sorted by UserId so I have to get the Username and the Display name from different services and different functions. Kinda weird.

Isn’t Username part of the UserInfo?

1 Like

Yes, but I’m given a username, not a UserId.

1 Like

Ah ok. Lapse in my consciousness.

1 Like

that is outdated use Players:GetPlayerByUserId

That only works if the player is in the game

4 Likes