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

How do i preload pictures? "ContentProvider:Preload()failed"

Asked by 6 years ago
Edited 6 years ago

Hello, im having trouble with a script that is supposed to preload pictures so that all pictures in my game will be loaded. However it's not working for me and it gives me one error evry time i run the script.

Error: "ContentProvider:Preload() failed"

It only gives me this error once however for one of the pictures and not the others. I don't know why, i tested changing the pictureId but it still gave me the error for that soundId.

I have looked around a lot on the internet about this but i haven't found anything that has made this work. The code is inside a script and not in a local script.

wait(0.5)

local ContentProvider = game:GetService("ContentProvider")

local function LoadAssets(AssetList)
    wait()
    for _, AssetId in ipairs(AssetList) do
        print(AssetId)
        ContentProvider:Preload("http://www.roblox.com/asset/?id=" .. AssetId)
    end
end

local Pics={}

for i,v in pairs(script.Parent:GetChildren())do
    if v:IsA("NumberValue")then
        table.insert(Pics,v.Value)
    end
end

LoadAssets(Pics)

I don't know what i have done wrong so help with this would be really appreciated, thanks.

EDIT:

I made this script:

wait(0.5)

print("DO")

local ContentProvider = game:GetService("ContentProvider")

local function LoadAssets(AssetList)
    wait()
    for _, AssetId in ipairs(AssetList) do
        print(AssetId)
        ContentProvider:PreloadAsync("http://www.roblox.com/asset/?id=" .. AssetId)
    end
end

local Pics={}

for i,v in pairs(game.Workspace.Values.MPics:GetChildren())do
    if v:IsA("StringValue")then
        table.insert(Pics,v.Value)
    end
end

LoadAssets(Pics)
repeat wait() until ContentProvider.RequestQueueSize <= 0
script:Remove()

But now it gives me the error: "unable to cast array".

I still don't know how this works..

0
You want to use PreloadASync with the instance using the assetID, not just the id http://wiki.roblox.com/index.php?title=API:Class/ContentProvider/PreloadAsync Vulkarin 581 — 6y
0
Firstly, Preload is deprecated. It's PreloadAsync. Secondly, the ContentProvider service is client only. You have to use it in a local script. Also, when using PreloadAsync, the argument is the instance, not the ID, like the first comment says. UgOsMiLy 1074 — 6y
0
i edited. bondhemlig 20 — 6y

Answer this question