InsertService

顯示已棄用項目

*此內容很快就會推出您所選的語言版本。

無法建立
服務

InsertService is used to insert assets from the Roblox website, typically the LoadAsset function.

To load an asset, it must be accessible by the creator of the experience loading it, which can be either a user or group. Should an experience be uploaded by a different creator, the asset data would not be accessible. See the LoadAsset() method for more details on this security check. Note that you should not use this service for loading API keys or other secrets. Use HttpService:GetSecret() instead.

See Also

  • AssetService, which can provide information about assets you might want to load using InsertService

概要

方法

屬性

AllowClientInsertModels

無法建立指令碼
平行讀取

方法

CreateMeshPartAsync

暫停

Creates a new MeshPart with specified CollisionFidelity and RenderFidelity. Because MeshPart.MeshId is read only, this is the way to create a MeshPart through scripts without having to clone an existing one. It throws errors if creation fails.

參數

meshId: ContentId

Mesh asset ID.


返回

New MeshPart instance.

GetFreeDecals

暫停

The GetFreeDecals function retrieves a list of free Decals from the Catalog. The return type for this method is very odd, as it returns a single table wrapped in a table.

The best way to explain it is to show a visual of the array returned:


[1] = {
CurrentStartIndex = 1, -- This can vary depending on the page you input.
TotalCount = 21, -- Always 21.
Results = {
-- All parameters here are pseudo. They can vary depending on the asset.
[1] = {
Name = "Asset Name",
AssetId = 0000000,
AssetVersionId = 0000000,
CreatorName = "Roblox",
},
-- [2], [3], and so on... up to [21]
},
}

An example for iterating over this list has been provided at the bottom of this page.

Additionally, if you want to insert Models instead, you can use the InsertService:GetFreeModels() function.

Note: The page argument starts at 0. So Page 1 = 0, Page 2 = 1, etc.

參數

searchText: string

String used to search for free decals in the Catalog.

pageNum: number

The page number in the Catalog to return.


返回

A single table (of returned free decals) wrapped in a table.

範例程式碼

InsertService:GetFreeDecals

local InsertService = game:GetService("InsertService")
local page = unpack(InsertService:GetFreeDecals("Cats", 0)) -- Search for "Cats" on Page 1.
for i = 1, page.TotalCount do
local item = page.Results[i]
print("Item #" .. i)
for key, value in pairs(item) do
print(" " .. key .. ": " .. value)
end
end

GetFreeModels

暫停

The GetFreeModels function retrieves a list of Free Models from the Catalog. The return type for this method is very odd, as it returns a single table wrapped in a table.

The best way to explain it is to show a visual of the array returned:


[1] = {
CurrentStartIndex = 1, -- This can vary depending on the page you input.
TotalCount = 21, -- Always 21.
Results = {
-- All parameters here are pseudo. They can vary depending on the asset.
[1] = {
Name = "Asset Name",
AssetId = 0000000,
AssetVersionId = 0000000,
CreatorName = "Roblox",
}
-- [2], [3], and so on... up to [21]
}
}

An example for iterating over this list has been provided at the bottom of this page.

Additionally, if you would like to insert free Decals, you can use the InsertService:GetFreeDecals() function.

參數

searchText: string

String used to search for free decals in the Catalog.

pageNum: number

The page number in the Catalog to return.


返回

A single table (of returned free models) wrapped in a table.

範例程式碼

InsertService:GetFreeModels

local InsertService = game:GetService("InsertService")
local page = unpack(InsertService:GetFreeModels("Cats", 0)) -- Search for "Cats" on Page 1.
for i = 1, page.TotalCount do
local item = page.Results[i]
print("Item #" .. i)
for key, value in pairs(item) do
print(" " .. key .. ": " .. value)
end
end

GetLatestAssetVersionAsync

暫停

Returns the latest AssetVersionId of an asset for assets created by the place creator. Can be used in combination with InsertService:LoadAssetVersion() to load the latest version of a model, even if it gets updated while the game is running.

參數

assetId: number

返回

LoadAsset

暫停

The LoadAsset function fetches an asset given its ID and returns a Model containing the asset. For example, to load this public Doge Model, which has the asset ID 257489726, you can use:


local assetId = 257489726
local InsertService = game:GetService("InsertService")
local model = InsertService:LoadAsset(assetId)
model.Parent = workspace

Calls to this function may fail if a server providing a model is having problems. As such, it's generally a good idea to wrap calls to this function in pcall to catch these kinds of errors.


local assetId = 257489726
local InsertService = game:GetService("InsertService")
local success, model = pcall(InsertService.LoadAsset, InsertService, assetId)
if success and model then
print("Model loaded successfully")
model.Parent = workspace
else
print("Model failed to load!")
end

Security Check

An asset loaded by this function must be created or owned by either the game creator or Roblox. Additionally, benign asset types such as t-shirts, shirts, pants and avatar accessories are loadable from any game as they are public.

See also:

參數

assetId: number

The asset ID of the asset being loaded.


返回

An instance of the loaded asset.

範例程式碼

InsertService:LoadAsset

local InsertService = game:GetService("InsertService")
local ASSET_ID = 82353
local asset = InsertService:LoadAsset(ASSET_ID)
asset.Parent = workspace

LoadAssetVersion

暫停

Returns a model inserted into InsertService containing the asset with the given assetVersionId.

參數

assetVersionId: number

返回

範例程式碼

InsertService:LoadAssetVersion

local InsertService = game:GetService("InsertService")
local ASSET_VERSION_ID = 296050499
local asset = InsertService:LoadAssetVersion(ASSET_VERSION_ID)
asset.Parent = game.Workspace

活動