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

I'm having a problem with Image preloading? I get an error [help?]

local Module= require(game:GetService("ReplicatedStorage").Module)
local ContentProvider = game:GetService("ContentProvider")

for i,v in pairs(Module.RankInfo) do
	local newImage = Instance.new("ImageLabel")
	newImage.Name = "PreloadedImage"
	newImage.Image = "rbxassetid://"..v.ImageId
	newImage.Parent = game:GetService("ServerStorage").Preloading
    
    ContentProvider:PreloadAsync(newImage)
end

I'm trying to preload my images for a Gui. Anyways, they don't preload at all. I get this error: Unable to cast array. I've been stuck on this for a good 20 minutes.

1 comment

1

That error means that v is an array. I'd check your module code.

1 answer

✓ Accepted answer

I think it’s not working because you need to preload the instance in an array. Trying to preload the instance itself won’t work.

You’ll probably have to do something like this for it to work :

-- Typed this on mobile so sorry if anything is wrong
local Module= require(game:GetService("ReplicatedStorage").Module)
local ContentProvider = game:GetService("ContentProvider")
local preloadtable = {}

for i,v in pairs(Module.RankInfo) do
    local newImage = Instance.new("ImageLabel")
    newImage.Name = "PreloadedImage"
    newImage.Image = "rbxassetid://"..v.ImageId
    newImage.Parent = game:GetService("ServerStorage").Preloading
    table.insert(preloadtable, newImage)

    ContentProvider:PreloadAsync(preloadtable) -- I recommend putting this below the for loop, but I think this works
end

I created a table (or array I guess), and used table.insert to put the created instance into the table. It should now preload with no errors as it’s preloading an array.

Hoped this helped!

Also here’s a helpful link to learn a little more about PreloadAsync :

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

3 comments

0

Alright now I get this error for every image... "ContentProvider:PreloadAsync() failed for rbxassetid://1963641401" The asset id is different though.

0

^ I think that's coming from the ModuleScript. Try subtracting the ID by one and see if it works. If it happens for any other ID, subtract those by one too.

0

When I subtract it by one, It still happens...

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