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

Unable to preload a texture help?

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"

1 comment

0

Line 14 - table.insert(assets, thing.Texture)

1 answer

✓ Accepted answer
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

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