Username from UserId

This seems so simple, yet I just can’t figure it out. Maybe I’m overlooking something. It’s easy to get UserId from Username but not the other way around. If I understand correctly, I need to use HttpService to do something as simple as this. I tried using api.roblox.com but got “Trust check failed”.

I have to use their UserId as their DataStore key in case they change their name but then when my leaderboard gets the data, I’m stuck with a UserId and no username to display.

1 Like

There is a Async Function under PlayerService that allows you to obtain the UserID from username.

https://developer.roblox.com/api-reference/function/Players/GetUserIdFromNameAsync

As Syo_1 said, there’s a method to do what you are looking for. You’re not allowed to send HTTP requests to any website ending in .roblox.com. These APIs are meant for usage in other applications, not games.

Yeah I use that all the time, that’s the easy one. My problem is getting the Username from the UserId.

There’s an API for this too, GetNameFromUserIdAsync.

7 Likes

Thanks so much, I don’t know how I’ve never seen this.

It’s very easy to overlook things, believe me, I do it all the time. lol

3 Likes

Note: As the documentation states, remember to use pcall since this makes a web call (and any web calls have the potential of failing unexpectedly)

6 Likes

Thanks for this info!