To get a user’s thumbnail (profile icon) you would use game.Players:GetUserThumbnailAsync(), but it is pretty slow (about 300 miliseconds)
Here’s an alternative that returns the thumbnail instantly:
function getUserThumbnailFast(userId: number, thumbnailType: Enum.ThumbnailType, thumbnailSize: Enum.ThumbnailSize)
local typeName
if thumbnailType == Enum.ThumbnailType.HeadShot then typeName = "AvatarHeadShot"
elseif thumbnailType == Enum.ThumbnailType.AvatarBust then typeName = "AvatarBust"
elseif thumbnailType == Enum.ThumbnailTypGetUserThumbnailFaste.AvatarThumbnail then typeName = "Avatar" end
return "rbxthumb://type="..(typeName or "AvatarHeadShot").."&id="..tostring(userId).."&w="..string.split(thumbnailSize.Name, "x")[2].."&h="..string.split(thumbnailSize.Name, "x")[2]
end
You can use it the same way as GetUserThumbnailAsync:
function getUserThumbnailFaster(userId: number, thumbnailType: Enum.ThumbnailType, thumbnailSize: Enum.ThumbnailSize)
if thumbnailType == Enum.ThumbnailType.AvatarThumbnail then
thumbnailType = "Avatar" else thumbnailType = "Avatar"..thumbnailType end
thumbnailSize = thumbnailSize.Name:split("x")
return "rbxthumb://type="..(thumbnailType or "AvatarHeadShot").."&id="..userId.."&w="..thumbnailSize[2].."&h="..thumbnailSize[2]
end
Fixed and optimized. Since you care about a few ms.
I’ve seen a similar resource to this, so I’ll just reiterate what I said there.
Your system has no way to tell if the thumbnail is ready to use or not, i.e. it does not return the isReady Boolean flag which Players:GetUserThumbnailAsync() does. Therefore, you don’t know if the thumbnail will work or not.
The reason Players:GetUserThumbnailAsync() takes so long is because of the network request involved.
The thumbnail returned from yours won’t always be ‘immediately ready’, the same way the one returned from Players:GetUserThumbnailAsync() won’t always be immediately ready.
Therefore, it does not have the capability for the same level of security and handling as Players:GetUserThumbnailAsync(). I would recommend using the format system as a backup in case the network request fails. I do that quite a lot.
local formatthumb = "rbxthumb://type=AvatarHeadShot&w=150&h=150&id=%d+"
local userid = --id here
local thumbnail, isReady = select(2, xpcall(function()
return Players:GetUserThumbnailAsync(id, Enum.ThumbnailType.HeadShot, Enum.ThumbnailSize.Size150x150)
end, function()
return string.format(formatThumb, id), nil
end))
if (type(isReady) == "boolean") then --from players method
else --from your method
end
So to summarize, use Players:GetUserThumbnailAsync() when you want to make sure it is loaded, and use this GetUserThumbnailFAST method if you don’t really care if it is ready or not. Similar to RemoteEvent and UnreliableRemoteEvent. Is my analogy correct?
Makes sense. I asked my question because I get HTTP too many request errors when loading player thumbnails for a leaderboard. And since it is displayed really small, it wouldn’t really matter if it loads or not. In this case, using this fast method would be more favorable?
well, you can yield for requests without interrupting your main task of actually writing to the leaderboard. Don’t use an actor, use the illusion of mulitasking; that is, task.spawn and the like.