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

How to effectively use PreloadAsync() to preload images?

Asked by 5 years ago

The following code outputs a failure to preload all 3 images.

I am using the instances with the proper assetID property in the argument table. What else could be going wrong?

local ContentProvider = game:GetService("ContentProvider")
local map1Snippet = Instance.new("ImageLabel")
map1Snippet.Image = "https://www.roblox.com/asset/?id=3528637124"
local map2Snippet = Instance.new("ImageLabel")
map2Snippet.Image = "https://www.roblox.com/asset/?id=3521669949"
local map3Snippet = Instance.new("ImageLabel")
map3Snippet.Image = "https://www.roblox.com/asset/?id=3521668508"



local assetDic = {map1Snippet,map2Snippet,map3Snippet}

ContentProvider:PreloadAsync(assetDic)
0
Maybe your images can't load because they don't exist, that is what my game does when my images don't exist greatneil80 2647 — 5y
0
How can I ensure that they exist? I can see them in my library. It doesn't show that pending icon but idk if that means they are loaded. Phibonacci 37 — 5y

2 answers

Log in to vote
0
Answered by 5 years ago
Edited 5 years ago

What I would prefer is to create a folder somewhere and use a local script to load all the assets.

If there's an error with the script please let me know. I had to write this quickly.

Example:

local contentProvider = game:GetService("ContentProvider")
local assetFolder = script:WaitForChild("Textures") -- The folder of assets.

contentProvider:PreloadAsync(addToTable())

function addToTable()
    local assets = {}

    for _,v in pairs(assetFolder:GetChildren()) do
        table.insert(assets, v)
    end

    return assets
end

So to give the rundown on the script, it basically loops through a folder(or any object) grabs the assets, puts them into a table and returns it. Which you can see on line 11. It returns the table it creates when adding all the assets. So all we need to do is call the function.

0
I did it. It output the same error unfortunately. Phibonacci 37 — 5y
Ad
Log in to vote
0
Answered by 3 years ago
Edited 3 years ago

If im pretty sure that layout the for PreloadAsync would need a table. Ex: game:GetService("ContentProvider"):PreloadAsync({Assets})

Answer this question