PreloadAsync
This is a yielding function. When called, it will pause the Lua thread that called the function until a result is ready to be returned, without interrupting other scripts.
https://developer.roblox.com/en-us/api-reference/function/ContentProvider/PreloadAsync
local ContentProvider = game:GetService("ContentProvider")
-- Create some objects to be preloaded
local sound = Instance.new("Sound")
sound.SoundId = "rbxassetid://1838058421"
local decal = Instance.new("Decal")
decal.Texture = "rbxassetid://5447528495"
-- A table of various assets to preload (Instances or content)
local assets = {
decal,
sound,
"rbxassetid://5173222739",
"rbxthumb://type=Avatar&w=100&h=100&id=269323"
}
-- For demonstration, pre-load 50 random user's avatar thumbnails
for i = 1, 50 do
table.insert(assets, "rbxthumb://type=Avatar&w=100&h=100&id=" .. math.random(1,1000000))
end
-- Preload the content and time it
local startTime = os.clock()
ContentProvider:PreloadAsync(assets)
local deltaTime = os.clock() - startTime
print(("Preloading complete, took %.2f seconds"):format(deltaTime))