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

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

Asked by 5 years ago
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
That error means that v is an array. I'd check your module code. waifuSZN 123 — 5y

1 answer

Log in to vote
2
Answered by 5 years ago

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

0
Alright now I get this error for every image... "ContentProvider:PreloadAsync() failed for rbxassetid://1963641401" The asset id is different though. Sharkeedub 179 — 5y
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. User#20279 0 — 5y
0
When I subtract it by one, It still happens... Sharkeedub 179 — 5y
Ad

Answer this question