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

Why am I getting preload errors with my preload script?

Asked by 6 years ago

When executing the following code inside a normal script

Assets = {
    "https://web.roblox.com/library/1818131072/Gun-Reload",
    "https://web.roblox.com/library/1818128535/Gun-Sprint",
    "https://web.roblox.com/library/1818040825/The-real-aim"
}

game:GetService("ContentProvider"):PreloadAsync(Assets)

I get this error:

https://gyazo.com/eabd84fc7dfe7a1887e9cc9c5e10600f

Why?

2 answers

Log in to vote
0
Answered by
Vezious 310 Moderation Voter
6 years ago

You and saSlol2436 are doing it wrong. Roblox decided to change on how you preload assets. Now, you have to create the instance and link it to the content and then pass the instance. I think it's utterly stupid.

http://wiki.roblox.com/index.php?title=API:Class/ContentProvider/PreloadAsync

So here's what you gotta do. This will only work if all of your assets are images.

local ContentProvider = game:GetService("ContentProvider")
local Assets = {}

for i,Asset in pairs (Assets) do
    local ImageLabel = Instance.new("ImageLabel")
    ImageLabel.Image = Asset
    ContentProvider:PreloadAsync(ImageLabel)
end

It isn't tested because I can't be bothered to open RobloxStudio.

If this solved your problem, accept my answer or feel my wrath.

0
Didn't work either Professor_Boxtrot 136 — 6y
0
whats error? did you add your asset ids to the assets table Vezious 310 — 6y
0
No error, aside from the asset preload failure. And yes, I did everything correctly Professor_Boxtrot 136 — 6y
Ad
Log in to vote
-1
Answered by 6 years ago

What I think you have done wrong is that you haven't iterated (or a fancy word for loop) the array (just another word for table or list). I just added two more lines of code.

local Assets = {
    "https://web.roblox.com/library/1818131072/Gun-Reload",
    "https://web.roblox.com/library/1818128535/Gun-Sprint",
    "https://web.roblox.com/library/1818040825/The-real-aim"
}

for _,asset in pairs(Assets) do
    game:GetService("ContentProvider"):PreloadAsync(asset)
end

By the way, I recommend using local variables when declaring them because they are slightly faster than a variable that is declared without the local syntax

Please accept this answer if it helped you

0
If you attempt to PreloadAsync just one thing, it says "Failed to cast to array" Professor_Boxtrot 136 — 6y
0
oh saSlol2436 716 — 6y

Answer this question