Avatar Creation Service
Summary
Methods
Events
AvatarAssetModerationCompleted(assetId: number,moderationStatus: Enum.ModerationStatus):RBXScriptSignal |
AvatarModerationCompleted(outfitId: number,moderationStatus: Enum.ModerationStatus):RBXScriptSignal |
AvatarOutfitModerationCompleted(outfitId: number,moderationStatus: Enum.ModerationStatus,outfitType: Enum.OutfitType):RBXScriptSignal |
API Reference
Methods
Auto Setup Avatar Async
Returns
Code Samples
AutoSetupAvatarAsync
local AvatarCreationService = game:GetService("AvatarCreationService")
local Players = game:GetService("Players")
local ReplicatedStorage = game:GetService("ReplicatedStorage")
local LoadAvatarEvent = ReplicatedStorage.LoadAvatarEvent
local generatedAvatars = {}
-- Must be called on the server
local function setupAvatar(player: Player, avatarModel: Model, layeredShirtModel : Model)
local arguments = {
Body = avatarModel,
Accessories = {}
}
local accessoryArgument = {
AccessoryType = Enum.AccessoryType.Shirt,
IsLayered = true,
Instance = layeredShirtModel,
}
table.insert(arguments.Accessories, accessoryArgument)
local pcallSuccess, result = pcall(function()
local generationId = AvatarCreationService:AutoSetupAvatarAsync(
player,
arguments,
function(progressInfo)
print(`AutoSetup progress: {progressInfo.Progress * 100}%`)
end
)
-- Load and store on the server to use with PromptCreateAvatarAsync
local humanoidDescription = AvatarCreationService:LoadGeneratedAvatarAsync(generationId)
generatedAvatars[generationId] = humanoidDescription
-- Signal the client so it can load the avatar for local preview
LoadAvatarEvent:FireClient(player, generationId)
end)
if not pcallSuccess then
warn("Avatar setup failed:", result)
end
end
Players.PlayerAdded:Connect(function(player)
setupAvatar(player, workspace.AvatarModel, workspace.LayeredShirtModel)
end)Generate Avatar2 D Preview Async
Avatar Creation Service: Generate Avatar2 D Preview Async(
Parameters
Returns
Code Samples
Generate Avatar2 D Preview Async
local AvatarCreationService = game:GetService("AvatarCreationService")
local Players = game:GetService("Players")
local ReplicatedStorage = game:GetService("ReplicatedStorage")
local previewReadyEvent = Instance.new("RemoteEvent")
previewReadyEvent.Name = "AvatarPreviewReady"
previewReadyEvent.Parent = ReplicatedStorage
function generateAvatar2DPreview(player, sessionId, fileId, textPrompt)
local pcallSuccess, result = pcall(function()
local args = {}
args.SessionId = sessionId
args.FileId = fileId
args.TextPrompt = textPrompt
return AvatarCreationService:GenerateAvatar2DPreviewAsync(args)
end)
if not pcallSuccess then
warn("Generating 2D preview failed: ", result)
return nil
end
-- The client passes this previewId to LoadAvatar2DPreviewAsync
previewReadyEvent:FireClient(player, result)
return result
end
Players.PlayerAdded:Connect(function(player)
-- Use the session ID from RequestAvatarGenerationSessionAsync and the file ID from PromptSelectAvatarGenerationImageAsync
generateAvatar2DPreview(player, "SESSION_ID", "FILE_ID", "A knight in shining armor")
end)Generate Avatar Async
Avatar Creation Service: Generate Avatar Async(
Parameters
Returns
Code Samples
Generate Avatar Async
local AvatarCreationService = game:GetService("AvatarCreationService")
function generateAvatar(sessionId, previewId)
local pcallSuccess, result = pcall(function()
local args = {}
args.SessionId = sessionId
args.PreviewId = previewId
return AvatarCreationService:GenerateAvatarAsync(args)
end)
if not pcallSuccess then
warn("Generating avatar failed: ", result)
end
return result
end
-- Example call with placeholder IDs
generateAvatar("session-id", "preview-id")Get Batch Token Details Async
Load Avatar2 D Preview Async
Parameters
Returns
Code Samples
Load Avatar2 D Preview Async
local AvatarCreationService = game:GetService("AvatarCreationService")
local ReplicatedStorage = game:GetService("ReplicatedStorage")
-- The server fires this event with the previewId that GenerateAvatar2DPreviewAsync returned
local previewReadyEvent = ReplicatedStorage:WaitForChild("AvatarPreviewReady")
function loadAvatar2DPreview(previewId)
local pcallSuccess, result = pcall(function()
return AvatarCreationService:LoadAvatar2DPreviewAsync(previewId)
end)
if not pcallSuccess then
warn("Failed to load preview: ", result)
return nil
end
return result
end
previewReadyEvent.OnClientEvent:Connect(function(previewId)
local previewImage = loadAvatar2DPreview(previewId)
if previewImage then
print("Loaded a preview image of size", previewImage.Size)
end
end)Load Generated Avatar Async
Parameters
Returns
Code Samples
LoadGeneratedAvatarAsync
local AvatarCreationService = game:GetService("AvatarCreationService")
local Players = game:GetService("Players")
-- Can be called on either the server or client
local function loadAvatar(generationId: string): Model?
local pcallSuccess, result = pcall(function()
local humanoidDescription = AvatarCreationService:LoadGeneratedAvatarAsync(generationId)
local model = Players:CreateHumanoidModelFromDescriptionAsync(humanoidDescription, Enum.HumanoidRigType.R15)
return model
end)
if pcallSuccess then
return result
else
print("Avatar failed to load:", result)
return nil
end
end
-- The generationId comes from AutoSetupAvatarAsync
local avatar = loadAvatar("generation-id")
if avatar then
avatar.Parent = workspace
endPrepare Avatar For Preview Async
Prompt Create Avatar Asset Async
Avatar Creation Service: Prompt Create Avatar Asset Async(
Parameters
Returns
Code Samples
PromptCreateAvatarAssetAsync
local AvatarCreationService = game:GetService("AvatarCreationService")
local Players = game:GetService("Players")
local function publishAvatarAsset(tokenId: string, player: Player, assetInstance: Accessory, assetType: Enum.AvatarAssetType)
local pcallSuccess, result, resultMessage = pcall(function()
return AvatarCreationService:PromptCreateAvatarAssetAsync(tokenId, player, assetInstance, assetType)
end)
if pcallSuccess then
if result == Enum.PromptCreateAssetResult.Success then
print("Successfully uploaded with AssetId: ", resultMessage)
else
print("Unsuccessfully uploaded with error message:", resultMessage)
end
else
print("Avatar asset failed to create.")
end
end
-- Replace the token with a creation token for this experience's universe, and the accessory with the asset to create
Players.PlayerAdded:Connect(function(player)
local accessory = Instance.new("Accessory")
publishAvatarAsset("TOKEN_ID", player, accessory, Enum.AvatarAssetType.Hat)
end)Prompt Create Avatar Async
Avatar Creation Service: Prompt Create Avatar Async(
Parameters
Returns
Code Samples
PromptCreateAvatarAsync
local AvatarCreationService = game:GetService("AvatarCreationService")
local Players = game:GetService("Players")
export type BodyPartInfo = {
bodyPart: Enum.BodyPart,
instance: Instance, --Folder with Created MeshParts
}
export type BodyPartList = { BodyPartInfo }
local function publishAvatar(bodyPartInstances: BodyPartList, player: Player, tokenId: string)
local humanoidDescription = Instance.new("HumanoidDescription")
for _, bodyPartInfo in bodyPartInstances do
local bodyPartDescription = Instance.new("BodyPartDescription")
bodyPartDescription.Instance = bodyPartInfo.instance
bodyPartDescription.BodyPart = bodyPartInfo.bodyPart
bodyPartDescription.Parent = humanoidDescription
end
local pcallSuccess, result, resultMessage = pcall(function()
return AvatarCreationService:PromptCreateAvatarAsync(tokenId, player, humanoidDescription)
end)
if pcallSuccess then
if result == Enum.PromptCreateAvatarResult.Success then
print("Successfully uploaded with BundleId: ", resultMessage)
else
print("Unsuccessfully uploaded with error message:", resultMessage)
end
else
print("Avatar failed to create.")
end
end
Players.PlayerAdded:Connect(function(player)
local bodyPartInstances: BodyPartList = {} -- Fill with your created body parts
publishAvatar(bodyPartInstances, player, "TOKEN_ID")
end)Prompt Create Makeup Async
Prompt Select Avatar Generation Image Async
Request Avatar Generation Session Async
Returns
Code Samples
Request Avatar Generation Session Async
local AvatarCreationService = game:GetService("AvatarCreationService")
local playerSessions = {}
local playerSessionRequests = {}
function requestAvatarGenerationSession(player)
local pcallSuccess, conn, waitTime = pcall(function()
return AvatarCreationService:RequestAvatarGenerationSessionAsync(player, function(sessionInfo)
playerSessions[player.UserID] = sessionInfo
playerSessionRequests[player.UserID] = nil
end)
end)
if not pcallSuccess then
warn("Failed to request Avatar generation session: ", conn)
end
playerSessionRequests[player.UserID] = conn
print("Wait time for session: ", tostring(waitTime))
end
function cancelAvatarGenerationSessionRequest(player)
if playerSessionRequests[player.UserID] ~= nil then
playerSessionRequests[player.UserID]:Disconnect()
end
end
game:GetService("Players").PlayerAdded:Connect(requestAvatarGenerationSession)
game:GetService("Players").PlayerRemoving:Connect(cancelAvatarGenerationSessionRequest)Validate UGC Accessory Async
Avatar Creation Service: Validate UGC Accessory Async(
Parameters
| Default Value: nil |
| Default Value: nil |
| Default Value: Unknown |
Returns
Validate UGC Body Part Async
Avatar Creation Service: Validate UGC Body Part Async(
Parameters
| Default Value: nil |
| Default Value: nil |
| Default Value: Head |
Returns
Validate UGC Full Body Async
Avatar Creation Service: Validate UGC Full Body Async(
Parameters
| Default Value: nil |
| Default Value: nil |
Returns
Events
Avatar Asset Moderation Completed
Avatar Creation Service. Avatar Asset Moderation Completed(
Parameters
Code Samples
Avatar Asset Moderation Completed
local AvatarCreationService = game:GetService("AvatarCreationService")
AvatarCreationService.AvatarAssetModerationCompleted:Connect(function(assetId, moderationStatus)
print("Asset, " .. assetId .. ", ready with moderation status: " .. moderationStatus)
end)Avatar Moderation Completed
Avatar Outfit Moderation Completed
Avatar Creation Service. Avatar Outfit Moderation Completed(
Parameters