Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
COMMUNITY QUESTION

Why am I getting preload errors with my preload script?

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 comments

0

Didn't work

2 answers

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.

3 comments

0

Didn't work either

0

whats error? did you add your asset ids to the assets table

0

No error, aside from the asset preload failure. And yes, I did everything correctly

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

2 comments

0

If you attempt to PreloadAsync just one thing, it says "Failed to cast to array"

0

oh

This discussion is preserved as it was. New answers, comments, and votes are closed.