GetUserThumbnailFAST

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:

game.Players:GetUserThumbnailAsync(1, Enum.ThumbnailType.HeadShot, Enum.ThumbnailSize.Size100x100)

becomes

getUserThumbnailFast(1, Enum.ThumbnailType.HeadShot, Enum.ThumbnailSize.Size100x100)

WARNING: the only disadvantage is that roblox can change how thumbnail IDs work, and getUserThumbnailFast will have to be updated manually

11 Likes

Nice system, although 300ms isn’t much of a difference. I do know some developers might need this!

1 Like
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.

5 Likes

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
4 Likes

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?

honestly, i dont tend to use unreliableremoteevent, so i cant really say.

this fast method doesn’t use the network request, hence it is faster, but it’s probably best to stick to the network request (Players method).

Either use the “fast” method as a backup in case the network request fails, or call it when the player joins and cache the result.

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?

Likely. You could always run the thumbnail retrievers on a separate thread to get around the limit if you wanted.

I wouldn’t worry too much about whether or not the thumbnail loads, especially for a leaderboard.

1 Like

How would retrieving thumbnails on a separate get around the limit? Why would a separate thread matter?

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.

Just yield when you hit a rate limit.

Ah, right, thanks for the clarification.

1 Like

Wouldn’t not using enums and directly using the number/string instead be faster?

1 Like

Coming back to say im gonna use this!

You could also use separated arguments for the X and Y, but this field is for look appeal rather than optimizations

2 Likes

Oddly similar to this: Other way to get the thumbnail of a user