How to get the User thumbnail without pausing the script?

My server supports 10 users.
All Ids of the users who belong to this server are saved in a DataStore, for future reference.
I can’t store users’ thumbnails in the DataStore, because they can change, so I only store the UserId.

I have a frame that shows the list of all users who belong to this server (even if they are not online).
Players | Roblox Creator Documentation pauses the script until the thumbnail is recovered.
Even storing the thumbnail in a cache for later use, at least for the first time, it will yield.
So if it takes about 1 second to get each thumbnail, if I have 10 users, my script will pause for 10 seconds.

My question is if is there any way to get the thumbnails for the first time in a parallel process, without interrupting the script?

You should check out coroutines.

3 Likes

which is here on the developer hub coroutine | Roblox Creator Documentation

2 Likes

Or you can use task.spawn(function) if you don’t plan to start and stop the script

1 Like

Use coroutines

for _, Player in pairs(Players) do
    coroutine.wrap(function()
        UpdateUserThumbnail()
    end)()
end
2 Likes

Perfect, thanks.
However, I see no need for those final ()

You actually need those. coroutine.wrap actually returns a function (just, not the typical ones), kinda like loadstring does. You need to add the () to actually run the code.

1 Like

Sorry, you’re right, now I see, thanks.

1 Like

If you want it to be faster, use ipairs instead