Asset Service
Summary
Properties
Methods
API Reference
Properties
Methods
Compose Decal Async
Returns
()
Code Samples
Compose a Decal
local AssetService = game:GetService("AssetService")
-- Create two decal instances
local decalA = Instance.new("Decal")
local decalB = Instance.new("Decal")
-- Build composite info table
local compositeInfo = {
{
ColorMap = decalA.ColorMapContent,
RoughnessMap = decalA.RoughnessMapContent,
MetalnessMap = decalA.MetalnessMapContent,
NormalMap = decalA.NormalMapContent,
},
{
ColorMap = Content.fromAssetId(123456),
RoughnessMap = decalB.RoughnessMapContent,
MetalnessMap = decalB.MetalnessMapContent,
NormalMap = decalB.NormalMapContent,
}
}
-- Create a decal to compose onto
local compositeDecal = Instance.new("Decal")
-- Compose an existing decal using AssetService
local success, errorMessage = pcall(function()
AssetService:ComposeDecalAsync(compositeDecal, compositeInfo)
end)
if success then
print("Decal composed successfully!")
-- Logic to show/use the decal goes here
else
warn("Failed to compose decal:", errorMessage)
endCreate Asset Async
Asset Service: Create Asset Async(
Parameters
| Default Value: nil |
Returns
Code Samples
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}`)
endCreate Asset Version Async
Asset Service: Create Asset Version Async(
Parameters
| Default Value: nil |
Returns
Code Samples
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}`)
endCreate Data Model Content Async
Parameters
Returns
Create Decal Async
Create Editable Image
Parameters
Returns
Create Editable Image Async
Asset Service: Create Editable Image Async(
Parameters
Returns
Create Editable Mesh
Parameters
Returns
Create Editable Mesh Async
Parameters
Returns
Create Mesh Part Async
Parameters
| Default Value: nil |
Returns
Create Place Async
Create Place In Player Inventory Async
Create Surface Appearance Async
Parameters
Returns
Code Samples
AssetService:CreateSurfaceAppearanceAsync
local AssetService = game:GetService("AssetService")
local Workspace = game:GetService("Workspace")
-- Green color - Editable Image Content
local colorEditableImage = AssetService:CreateEditableImage({ Size = Vector2.new(4, 4) })
colorEditableImage:DrawRectangle(Vector2.zero, colorEditableImage.Size, Color3.fromRGB(0, 255, 0), 0, Enum.ImageCombineType.Overwrite)
-- Emissive (only look at the red channel) - DataModel Content
local mapSize = 128
local quarterMapSize = mapSize / 4
local emissiveEditableImage = AssetService:CreateEditableImage({ Size = Vector2.new(mapSize, mapSize) })
-- Create a circle pattern by making the entire background have an emissive value of 0, and two circles on opposite sides have an emissive value of 1.
emissiveEditableImage:DrawRectangle(Vector2.zero, emissiveEditableImage.Size, Color3.new(0, 0, 0), 0, Enum.ImageCombineType.Overwrite)
emissiveEditableImage:DrawCircle(Vector2.new(quarterMapSize, quarterMapSize*3), quarterMapSize, Color3.new(1, 0, 0), 0, Enum.ImageCombineType.Overwrite)
emissiveEditableImage:DrawCircle(Vector2.new(quarterMapSize*3, quarterMapSize), quarterMapSize, Color3.new(1, 0, 0), 0, Enum.ImageCombineType.Overwrite)
local dmcResult, emissiveDataModelContent = AssetService:CreateDataModelContentAsync(Content.fromObject(emissiveEditableImage))
assert(dmcResult == Enum.CreateContentResult.Success)
-- Metalness (only look at the red channel) - Asset ID Content
local METALNESS_ASSET_ID = "rbxassetid://658743164"
local surfaceAppearance = AssetService:CreateSurfaceAppearanceAsync({
ColorMap = Content.fromObject(colorEditableImage),
EmissiveMask = emissiveDataModelContent,
MetalnessMap = Content.fromUri(METALNESS_ASSET_ID)
})
-- You can still change most properties other than the Content used for the maps and EmissiveMask.
surfaceAppearance.EmissiveStrength = 20
local meshPart = AssetService:CreateMeshPartAsync(Content.fromAssetId(16799342206))
meshPart.Parent = Workspace
meshPart.Anchored = true
meshPart.Position = Vector3.new(0, 2, 0)
-- Apply surface appearance to mesh part
surfaceAppearance.Parent = meshPartGet Asset Ids For Package
Get Asset Ids For Package Async
Get Audio Metadata Async
Parameters
Returns
Code Samples
Get Audio Metadata
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
endGet Bundle Details Async
Parameters
Returns
Code Samples
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"
}
--]]
endGet Creator Asset ID
Get Game Places Async
Returns
Code Samples
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()
endLoad Asset Async
Prompt Create Platform Content Async
Asset Service: Prompt Create Platform Content Async(
Parameters
Returns
Prompt Import Animation Clip From Video Async
Save Place Async
Parameters
Returns
()
Search Audio
Search Audio Async
Parameters
Returns
Code Samples
Getting Music Search Titles
local AssetService = game:GetService("AssetService")
local audioSearchParams = Instance.new("AudioSearchParams")
audioSearchParams.SearchKeyword = "happy"
local success, result = pcall(function()
return AssetService:SearchAudioAsync(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
}
}
--]]