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

LoadAsset

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:

InsertService:LoadAsset(257489726)

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.

Packages

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.

Error-catching

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

See also

To find Free Models or Decal|Decals to insert into your game, you can use the InsertService/GetFreeModels and InsertService/GetFreeDecals functions. For plugins, see DataModel/GetObjects.

Parameters

Name Type Default Description

The asset Id of the asset being loaded

Returns

Return Type Summary

An instance of the loaded asset


Code Samples


InsertService:LoadAsset

local assetId = 82353
game:GetService("InsertService"):LoadAsset(assetId).Parent = game.Workspace