Get Player from ID

I came across a six year old solution on scripting helpers:

but the provided code:

function UserFromId(userId)
local userSets = game:GetService("InsertService"):GetUserSets(userId) --get the user's sets
for _,v in pairs(userSets) do --iterate through then
if v.Name == "My Models" then --check if  this is the player's models
return v.CreatorName --returning the name of the creator of the set "My Models" (the player)
end
end
end

print(UserFromId(261))

seems clunky and improper.

I was wondering if there is a more proper way to do this, but as of yet exploring what InsertService | Documentation - Roblox Creator Hub can fetch for me, I haven’t found anything.

You got GetNameFromUserIdAsync

It would go something like this

local UserId = 93937677
local PlayerNameFromId = game.Players:GetNameFromUserIdAsync(UserId)
print(PlayerNameFromId) --> uhi_o

There’s also GetPlayerByUserId which returns the player object rather than a string of the player’s name.

Edit: You can also use the API with a Http request https://api.roblox.com/docs#Users

6 Likes