PcoWSkbVqDnWTu_dm2ix
We use cookies on this site to enhance your user experience
Collapse Sidebar

PreloadAsync

The PreloadAsync function takes an array of Instances as a parameter and yields until all of assets associated with those instances have loaded. This can be used to pause a script and not use content until it is certain that the content has been loaded into the game.

When the function is called, the engine will go through all of the instances in the passed in array (and all of the descendants of the passed in instances). If any of the instances have a property that defines a link to content, such as a Decal or a Sound, then the function will attempt to load the asset from the Roblox website. If any of the assets fail to load, an error message will appear in the places output, but the PreloadAsync function itself will not error and will continue executing until it has processed each passed in instance.

Parameters

Name Type Default Description

An array of Instances to be preloaded.

Returns

Return Type Summary

Code Samples


ContentProvider:PreloadAsync

In this example a Decal and Sound are preloaded into a game. Once they have finished loading the script will print a message to the output.

local ContentProvider = game:GetService("ContentProvider")

local logoId = "rbxassetid://658743164"
local pageTurnId = "rbxassetid://12222076"

local decal = Instance.new("Decal")
decal.Texture = logoId

local sound = Instance.new("Sound")
sound.SoundId = pageTurnId

local assets = { decal, sound }

ContentProvider:PreloadAsync(assets)

print("All assets loaded.")