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.
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