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

Does PreloadAsync() work with IDs?

Asked by 3 years ago
Edited 3 years ago

I've been using PreloadAsync() to load all of my Gui elements, since most of them are made of a lot of images, but sometimes it looks like assets still need time to load. I wrote my table like this:

local AssetTable = {
    "rbxassetid://"..-- This is the way I've been Preloading assets, using IDs instead of instances
    --+70 IDs that I won't copy
}

I saw some people saying that PreloadAsync() only works when using Instances and not IDs(?), but I've seen people using IDs and even the API Reference uses as an example strings of assets, not Instances on the game.

On my callback function I made a simple counter that helps printing how many assets where loaded and how many failed (if any):

function callback(contentId, status)
    if status == Enum.AssetFetchStatus.Success then
        LoadedAssets = LoadedAssets + 1     
    end
    if status == Enum.AssetFetchStatus.Failure then
        FailedAssets = FailedAssets + 1
        table.insert(WebPageFailedTable, WebPageFailedAssets, contentId) --Simple table I made in order for the failed assets to appear as a list when printing them in a "In Pairs" loop 
    end
end

--Later in the script

warn(tonumber(LoadedAssets).." assets were correctly loaded!")

if FailedAssets > 0 then
    warn(tonumber(FailedAssets).."  assets were unable to load!:")
    for i, Asset in pairs(FailedTable) do
        warn(tonumber(i)..": "..tostring(Asset))
    end
else
    warn("All assets were loaded successfully!")
end

Output:

72 assets were correctly loaded!

All assets were loaded successfully!

Yet I when my loading screen goes off, sometimes assets I included take time to load. Keep in mind my PC is incredibly old, but I still have doubts if PreloadAsync() works with IDs, Instances, or both. So please if someone can put my doubts to rest I would really appreciate it.

Answer this question