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.
This function takes an array of Instance|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 |
||
nil
|
The Lua function to be called on completion of each asset request |
Returns
Return Type | Summary |
---|---|
No return |
Code Samples
Preloading Assets
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.