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

Unable to preload a texture help?

Asked by
NotSoNorm 777 Moderation Voter
8 years ago

so pretty much the script goes through and finds a whole bunch of textures through the game then starts to preload them, but I keep getting this error: Unable to cast Instance to Content | Script 'Players.Player.PlayerScripts.IntroMain', Line 22

local assets = {}
local loaded = false

function descendants(model, list)
    list = list or {}
    for _, child in pairs(model:GetChildren()) do
        table.insert(list, child)
        descendants(child, list)
    end
    return list
end
for _, thing in pairs( descendants(workspace) ) do
    if thing:IsA("Decal") then
        table.insert(assets, thing)
    end
end
loadtext.LoadingAssetsLabel.Text = "Found assets: "..#assets wait(1)
loadtext.LoadingAssetsLabel.Text = "We're loading your assets, hold tight." wait(1)

content = game:GetService("ContentProvider")
for _, asset in ipairs(assets) do
    game:GetService("ContentProvider"):Preload(asset)
    repeat  wait()  until content.RequestQueueSize == 0
    loadtext.LoadingAssetsLabel.Text = asset
end
loaded = true
loadtext.LoadingAssetsLabel.Text = "Finished"
0
Line 14 - table.insert(assets, thing.Texture) Redbullusa 1580 — 8y

1 answer

Log in to vote
1
Answered by
Validark 1580 Snack Break Moderation Voter
8 years ago
for _, thing in pairs( descendants(workspace) ) do
    if thing:IsA("Decal") then
        table.insert(assets, thing) -- You are inserting an object into the assets table
    end
end

Here is how it should be written:

for _, thing in pairs( descendants(workspace) ) do
    if thing:IsA("Decal") then
        table.insert(assets, thing.Texture) -- You are inserting a texture into the assets table
    end
end

Ad

Answer this question