Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

Is there any way to yield a thread until HTTPService is able to take requests ?

Asked by
Cirillix 110
2 years ago

I basically have a function here that loads a player's username via their userid. The problem is that it will often error since :GetNameFromUserIdAsync() is an http request and I am looping through a lot of data that contains the player's user id. (No, I do not want to save the player's username as it could be outdated) Is there any way to wait until HTTPService can receive requests ?

local LoadUsername = coroutine.wrap(function()
        local success2, errorMessage2 = pcall(function()
             PlayerName.Text = tostring(game.Players:GetNameFromUserIdAsync(BlockTable.UserId)).."'s block"
        end)
        if not success2 then
            PlayerName.Text = "Username could not be fetched : ("..string.split(tostring(errorMessage2), "failed: ")[2]..")"
        end
    end)

Answer this question