I’m trying to use Content Provider to preload all images in a module script. And when I try, it says Unable to cast to array.
local function PreloadFailed(contentId, Status)
if Status == Enum.AssetFetchStatus.Failure then
error("Failed to load", contentId)
end
end
task.spawn(function()
ContentProvider:PreloadAsync(Images, PreloadFailed)
end)
Does anybody know how to fix this? Or, a better way to preload all assets in a modulescript?
local function PreloadFailed(contentId, Status)
if Status == Enum.AssetFetchStatus.Failure then
error("Failed to load: "..tostring(contentId)) -- Try this
end
end
task.spawn(function()
ContentProvider:PreloadAsync(Images, PreloadFailed)
end)
Sadly, that did not work. I have a feeling it has something to do with the fact I am trying to preload out of a module, and not a folder of some sort. (I’m trying to preload out of a module for optimization reasons.)
Oh, that makes sense. My end goal is to preload all the items in a module. I’m just referring to the module through require() if that makes sense. Is there any better way or any way to preload everything in a module without having to make an array in the local script?
for _,i in pairs({workspace:GetDescendants()}) do -- Goes through a Table with a Table
CProvider:PreloadAsync(i) -- Preloads Table with Descendants of the workspace
end
GetDescendants() returns a Table of all Descendants in the hirearchy
Ancestor – Parent of Parent (All Parents of the Instance and so on) Parent – Instances Parent Instance – Your Item Child – Instances Children Descendant – Children of Children ( All Items within the Instance )
you can do game:GetDescendants() but you might get errors for Accessing Locked Service’s