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.
The LoadAsset function fetches an asset given its ID and returns a
Model inserted into
InsertService containing the asset.
The given asset must be created by you or Roblox, otherwise the function will error.
For instance, if you want to load a Doge
Model, which has the asset Id 257489726, you would use the following statement:
This line would return an
Instance of the Doge model within your game. Changing the asset Id passed as an argument changes the asset that is loaded into your game.
There are limitations on loading packages. Use
AssetService/GetAssetIdsForPackage to get asset IDs of a package, then insert them one at a time using this function.
Occasionally, an asset may fail to load. It’s a good idea to wrap calls to this function in
pcall to catch these kinds of errors:
local success, model = pcall(function () return InsertService:LoadAsset(257489726) end) if success then print("Model loaded!") model.Parent = workspace else print("Model failed to load") end
To find Free Models or
Decal|Decals to insert into your game, you can use the
InsertService/GetFreeDecals functions. For plugins, see
The asset Id of the asset being loaded
An instance of the loaded asset