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.
For thread safety, this property is not safe to read in an unsynchronized thread.
Yields until all of the assets associated with the given Instance|Instances have loaded and takes an array of Instance|Instances as a parameter.
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 the array of instances (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 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 code sample, several textures and sounds are preloaded using Sound and Decal instances, as well as plain /articles/Content|Content. Furthermore, 50 random user avatars are preloaded.