AssetService

Mostrar obsoleto

*Pronto este contenido estará disponible en tu idioma seleccionado.

No creable
Servicio

AssetService is a non-replicated service that handles asset-related queries to the Roblox web API.

Resumen

Métodos

Propiedades

Métodos

CreateEditableImage

Creates a new EditableImage. By default, the resolution is set at 512×512, but you can specify a different size using the method's option table.

If the device‑specific editable memory budget is exhausted, creation fails and this method returns nil.

Parámetros

editableImageOptions: Dictionary

Options table containing controls for the method:

  • Size – A Vector2 that specifies the image's desired width and height.

Devuelve

CreateEditableMesh

Creates a new, empty EditableMesh. Vertices, triangles and their attributes can be added dynamically to it. If the device‑specific editable memory budget is exhausted, creation will fail and this method will return nil.

Parámetros

editableMeshOptions: Dictionary

Devuelve

CreateAssetAsync

Proporciona
Seguridad del plugin
Seguridad de OpenCloud

Creates a new asset from the given object in Plugin or Open Cloud Luau Execution context.

Parámetros

object: Object

The object to be created as an asset.

assetType: Enum.AssetType

Currently supported types are:

requestParameters: Dictionary

Options table containing asset metadata:

  • Name – Name of the asset as a string. Defaults to [object.Name].
  • Description – Description of the asset as a string. Defaults to "Created with AssetService:CreateAssetAsync".
  • CreatorId – ID of the asset creator as a number. Defaults to the logged in Roblox Studio user for Plugin context. Required for Open Cloud Luau Execution context.
  • CreatorTypeEnum.AssetCreatorType indicating the type of asset creator. Defaults to Enum.AssetCreatorType.User in Plugin context. Required for Open Cloud Luau Execution context.
  • IsPackage – Boolean value, only applicable to the Enum.AssetType.Model type. Defaults to true.

Devuelve

The Enum.CreateAssetResult and asset ID pair if successful.

Muestras de código

AssetService:CreateAssetAsync

local AssetService = game:GetService("AssetService")
local editableMesh = AssetService:CreateEditableMesh()
-- add vertices, faces, and uvs to the mesh
local requestParameters = {
CreatorId = 123,
CreatorType = Enum.AssetCreatorType.User,
Name = "My asset",
Description = "a good asset",
}
local ok, result, idOrUploadErr = pcall(function()
return AssetService:CreateAssetAsync(editableMesh, Enum.AssetType.Mesh, requestParameters)
end)
if not ok then
warn(`error calling CreateAssetAsync: {result}`)
elseif result == Enum.CreateAssetResult.Success then
print(`success, new asset id: {idOrUploadErr}`)
else
warn(`upload error in CreateAssetAsync: {result}, {idOrUploadErr}`)
end

CreateAssetVersionAsync

Proporciona
Seguridad del plugin
Seguridad de OpenCloud

Creates a new version for an existing asset from the given object in Plugin or Open Cloud Luau Execution context.

Parámetros

object: Object

The object to be created as an asset.

assetType: Enum.AssetType

Currently supported types are:

assetId: number

The ID of the asset for the new version.

requestParameters: Dictionary

Options table containing asset metadata:

  • Name – A string. Name of the asset. Default: object.Name.
  • Description – A string. Description of the asset. Default: "Created with AssetService:CreateAssetAsync".
  • CreatorId – A number. ID of the asset creator. Default: The logged in Roblox Studio user for Plugin context. Required for Open Cloud Luau Execution context.
  • CreatorType – A Enum.AssetCreatorType. Type of asset creator. Default: Enum.AssetCreatorType.User in Plugin context. Required for Open Cloud Luau Execution context.
  • IsPackage – A bool. Only applicable to the Enum.AssetType.Model type. Default: true.

Devuelve

The Enum.CreateAssetResult and asset version number pair if successful.

Muestras de código

AssetService:CreateAssetVersionAsync

local AssetService = game:GetService("AssetService")
local assetIdToUpdate = 321
local model = Instance.new("Model")
local requestParameters = {
CreatorId = 123,
CreatorType = Enum.AssetCreatorType.User,
}
local ok, result, versionOrUploadErr = pcall(function()
return AssetService:CreateAssetVersionAsync(model, Enum.AssetType.Model, assetIdToUpdate, requestParameters)
end)
if not ok then
warn(`error calling CreateAssetVersionAsync: {result}`)
elseif result == Enum.CreateAssetResult.Success then
print(`success, new asset version: {versionOrUploadErr}`)
else
warn(`upload error in CreateAssetVersionAsync: {result}, {versionOrUploadErr}`)
end

CreateEditableImageAsync

Proporciona

Creates a new EditableImage object populated with the given texture. Non-asset texture IDs such as rbxthumb:// are supported. If using an image asset, it must be associated with and/or owned by a creator of the experience, or it must have been created inside the experience. If the device-specific editable memory budget is exhausted, creation will fail and this method will return nil.

See the Enabling EditableImage for Published Experiences and Permissions sections of EditableImage for special considerations when using this API.

Parámetros

content: Content
editableImageOptions: Dictionary

Devuelve

A new EditableImage containing the provided image.

CreateEditableMeshAsync

Proporciona

Returns a new EditableMesh object created from an existing mesh content ID. By default a EditableMesh created from this method will be fixed size such that mesh data can only be modified, not added nor removed. A fixed size EditableMesh consumes less memory and should be preferred when possible.

If the device-specific editable memory budget is exhausted, creation will fail and this method will return nil.

See the Enabling EditableMesh for Published Experiences and Permissions sections of EditableMesh for special considerations when using this API.

Parámetros

content: Content
editableMeshOptions: Dictionary

Options table containing controls for the method:

  • FixedSize – A bool. Default value is true, and the returned EditableMesh will not allow you to add or remove vertices, only modify their values. Set to false if the ability to change the mesh topology is required, at the expense of using more memory.

Devuelve

The new EditableMesh instance.

CreateMeshPartAsync

Proporciona

This method creates a MeshPart with a specified CollisionFidelity, RenderFidelity, and FluidFidelity. Because MeshPart.MeshId is read only, this method is for creating a mesh with any mesh ID through scripts, without having to clone an existing MeshPart. It throws errors if creation fails.

Parámetros

meshContent: Content
options: Dictionary

Options table containing one or more controls for the method:

Valor predeterminado: "nil"

Devuelve

CreatePlaceAsync

Proporciona

Clones a place through the given templatePlaceID and returns the PlaceId of the new place, which you can use with TeleportService. The clone place displays within the inventory of the place's creator with the given name and description.

Note that the template place must have template copying enabled through place settings. You cannot use this method to clone places that you don't own.

Frequent use of this API is not recommended, particularly if the created places contain scripts, as updating the code in a large volume of places quickly becomes infeasible. For user-generated worlds, consider serializing user creations and saving them in DataStores instead.

Parámetros

placeName: string

Name of the new place.

templatePlaceID: number

PlaceId of the place to clone.

description: string

Description of the new place.

Valor predeterminado: ""

Devuelve

PlaceId of the new place.

CreatePlaceInPlayerInventoryAsync

Proporciona

Parámetros

player: Instance
placeName: string
templatePlaceID: number
description: string
Valor predeterminado: ""

Devuelve

GetAssetIdsForPackage

Proporciona

Returns an array of asset IDs that are contained in a specified package.

Parámetros

packageAssetId: number

Devuelve

Asset IDs that are contained in a specified package.

GetAudioMetadataAsync

Proporciona

Provides relevant metadata about a specific audio source (artist, title, duration, type, etc.).

Parámetros

idList: Array

Array of asset or content IDs for which to retrieve metadata. Max batch size is 30.


Devuelve

Array of dictionary tables in the same order as the request, where each dictionary contains the following metadata for its asset/content:

Note that if an error occurs on fetching metadata for any of the requested assets, for example the asset ID doesn't exist, its dictionary table is still included in the returned array but it only contains the AssetId field for reference purposes. Additionally, if the AudioType cannot be determined for a given asset (perhaps because it's private audio), the resulting dictionary will not contain an AudioType entry.

Muestras de código


local AssetService = game:GetService("AssetService")
local SoundService = game:GetService("SoundService")
local trackIDs = {
SoundService.Sound1.SoundId,
SoundService.Sound2.SoundId,
SoundService.Sound3.SoundId,
SoundService.Sound4.SoundId
}
local success, result = pcall(function()
return AssetService:GetAudioMetadataAsync(trackIDs)
end)
if success then
for i = 1, #trackIDs do
local contentId = "rbxassetid://" .. result[i].AssetId
if trackIDs[i] == contentId then
print(result[i].Title, "by", result[i].Artist)
else
warn("No metadata fetched for requested asset #" .. tostring(i))
end
end
end

GetBundleDetailsAsync

Proporciona

This function returns details of the contents of the specified bundle.

If the bundle ID does not exist, it throws HTTP 400 (Bad Request). If bundleId is not convertible to an integer, it throws Unable to cast string to int64.

Parámetros

bundleId: number

The ID of the specified bundle.


Devuelve

Dictionary with the following key-value pairs containing details about the specified bundle:

  • Id — Bundle ID (same as passed bundleId argument)

  • Name — Bundle name

  • Description — Bundle description

  • BundleType — String representing the Enum.BundleType, for example "BodyParts" or "DynamicHead"

  • Items — Array of items in the bundle, each with details represented through the following keys:

    • Id — Item ID

    • Name — Item name

    • Type — Item type such as "Asset" .

Muestras de código

Getting Bundle Details

local AssetService = game:GetService("AssetService")
local BUNDLE_ID = 14
local success, result = pcall(function()
return AssetService:GetBundleDetailsAsync(BUNDLE_ID)
end)
if success then
print(result)
--[[
{
["BundleType"] = "BodyParts",
["Description"] = "The year is 5003, Battlebot 5000 must face his mightiest foe, or face becoming obsolete.",
["Id"] = 14,
["Items"] = {
[1] = {...},
[2] = {
["Id"] = 1678225030,
["Name"] = "SinisterBot 5001 Left Arm",
["Type"] = "Asset"
},
[3] = {...},
[4] = {...},
[5] = {...},
[6] = {...},
[7] = {...}
},
["Name"] = "SinisterBot 5001"
}
--]]
end

GetGamePlacesAsync

Proporciona

Returns a StandardPages object which contains the name and PlaceId of places within the current experience.


Devuelve

Muestras de código

AssetService:GetGamePlacesAsync

local AssetService = game:GetService("AssetService")
local placePages = AssetService:GetGamePlacesAsync()
while true do
for _, place in placePages:GetCurrentPage() do
print("Name:", place.Name)
print("PlaceId:", place.PlaceId)
end
if placePages.IsFinished then
break
end
placePages:AdvanceToNextPageAsync()
end

PromptCreateAssetAsync

Proporciona

Allows in-experience asset creation for users by prompting a publish dialog. When called, it presents a dialog to the user, allowing them to enter a name, description, and preview the asset. Upon submitting, it saves the asset to the user's inventory. Can only be invoked on the server side.

Parámetros

player: Player

The user who submits an asset creation.

instance: Instance

The asset to be created. Currently can't contain scripts or nest non-public assets.

assetType: Enum.AssetType

The asset type. Currently can only be Enum.AssetType.Model.


Devuelve

The Enum.PromptCreateAssetResult and asset ID pair if successful.

PromptImportAnimationClipFromVideoAsync

Proporciona

Parámetros

player: Player
progressCallback: function

Devuelve

SavePlaceAsync

void
Proporciona

Saves the state of the current place. Only works for places that are created with AssetService:CreatePlaceAsync() or which have the API enabled through place settings.


Devuelve

void

SearchAudio

Proporciona

Returns a AudioPages object containing the result of the given search. Will not return fields with empty values.

Note that this method has a low HTTP request limit and can throw an error, so it should always be wrapped in pcall() for error handling. Possible error messages include:

Error MessageReason
HTTP 429 (Too Many Requests)AssetService:SearchAudio() has been called too many times.
Unexpected type for data, expected array got nullThe keyword argument was filtered.

Parámetros

searchParameters: AudioSearchParams

Devuelve

Muestras de código

Getting Music Search Titles

local AssetService = game:GetService("AssetService")
local audioSearchParams = Instance.new("AudioSearchParams")
audioSearchParams.SearchKeyword = "happy"
local success, result = pcall(function()
return AssetService:SearchAudio(audioSearchParams)
end)
if success then
local currentPage = result:GetCurrentPage()
for _, audio in currentPage do
print(audio.Title)
end
else
warn("AssetService error: " .. result)
end
--[[ Returned data format
{
"AudioType": string,
"Artist": string,
"Title": string,
"Tags": {
"string"
},
"Id": number,
"IsEndorsed": boolean,
"Description": string,
"Duration": number,
"CreateTime": string,
"UpdateTime": string,
"Creator": {
"Id": number,
"Name": string,
"Type": number,
"IsVerifiedCreator": boolean
}
}
--]]

Eventos