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

How would you preload assets in a folder?

Not sure how to do this. I have hundreds of decals to preload and I really don't want to do all of them one by one, so how would I just preload all assets of a folder in a simple few lines of code?

game:GetService("ContentProvider"):PreloadAsync(workspace.Folder:GetChildren())

This is some code I found from a different post, but it didn't seem to be working for me.

1 comment

0

As you see, you cannot just preload random instances as it will error.... You must preload its id's for example if you have a decal, then you should get it's ID and store it and then preload that way...

1 answer

✓ Accepted answer

This code searches through all of the decals in the folder and preloads them.

local textures = {}

for i,v in pairs(game:GetService("Workspace").Folder:GetChildren())
	if v:IsA("Decal") then
		table.insert(textures,v.Texture)
	end
end

game:GetService("ContentProvider"):PreloadAsync(textures)

5 comments

0

Actually, ContentProvider:PreloadAsync() takes an array of instances. game:GetService("ContentProvider"):PreloadAsync(workspace.Folder:GetChildren()) should work. https://developer.roblox.com/api-reference/function/ContentProvider/PreloadAsync

0

It wouldn't because the array has to be of asset id's of the textures.'rbxassetid://658743164' Also mine makes sure that all inputs are Decals like he stated.

0

Have you checked out the link? The api reference says otherwise.

0

Ok, they must have changed that recently. Still my way is safer as it makes sure that it is a Decal.

0

remove the if and then on line 4 and it works :)

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