# AvatarCreationService

Roblox Engine API class from Roblox Studio 0.744.0.7441077 (version-7aaa6838d36c4448).

- Inherits from, nearest first: [Instance](https://rapi.sleaze.dev/classes/Instance.md), [Object](https://rapi.sleaze.dev/classes/Object.md)
- Tags: Not creatable, Service
- Memory category: Instances
- HTML page: https://rapi.sleaze.dev/classes/AvatarCreationService/
- Roblox documentation: https://create.roblox.com/docs/reference/engine/classes/AvatarCreationService

A service to support developer avatar creators.

## Methods

### AutoSetupAvatarAsync

```luau
AvatarCreationService:AutoSetupAvatarAsync(player: Player, autoSetupParams: { [string]: any }, progressCallback: ((...any) -> ...any)?): string
```

- Tags: Yields, Capabilities: DynamicGeneration

Automatically sets up a custom [`Model`](https://rapi.sleaze.dev/classes/Model.md) and/or avatar accessories.

Parameters:

- `player`: The [`Player`](https://rapi.sleaze.dev/classes/Player.md) that the avatar is being set up for.
- `autoSetupParams`: A table containing the arguments. Type: `type AutoSetupAccessory = { AccessoryType: Enum.AccessoryType, IsLayered: bool, Instance: Model, } type AutoSetupParams = { Body: Model?, Accessories: {AutoSetupAccessory}, }`
- `progressCallback`: Optional callback function that will be invoked periodically with a progressInfo table with the overall progress (from 0 to 1). Type: `(progressInfo: { Progress: number }) -> ()`

Returns: A unique identifier for the generated avatar.

### CreateCageMeshPartsWithScaleForExportAsync

```luau
AvatarCreationService:CreateCageMeshPartsWithScaleForExportAsync(model: Model): Folder
```

- Tags: Yields, Roblox script security

### DeserializeAvatarModel

```luau
AvatarCreationService:DeserializeAvatarModel(serializedModel: string): Instance
```

- Tags: Roblox script security

### GenerateAvatar2DPreviewAsync

```luau
AvatarCreationService:GenerateAvatar2DPreviewAsync(avatarGeneration2dPreviewParams: { [string]: any }, progressCallback: ((...any) -> ...any)?): string
```

- Tags: Yields, Capabilities: DynamicGeneration

Creates a 2D avatar preview and returns a `previewId`.

Parameters:

- `avatarGeneration2dPreviewParams`: A table of arguments for 2D preview generation. Type: `avatarGeneration2dPreviewParams: {SessionId: string, FileId: string, TextPrompt: string?}`
- `progressCallback`: Optional callback function that will be invoked periodically with a progressInfo table with the overall progress (from 0 to 1). Type: `(progressInfo: { Progress: number }) -> ()`

Returns: A string previewId

### GenerateAvatarAsync

```luau
AvatarCreationService:GenerateAvatarAsync(avatarGenerationParams: { [string]: any }, progressCallback: ((...any) -> ...any)?): string
```

- Tags: Yields, Capabilities: DynamicGeneration

Generates an avatar and returns a generationId.

Parameters:

- `avatarGenerationParams`: A table of arguments for generating an avatar. Type: `avatarGenerationParams: {SessionId: string, PreviewId: string}`
- `progressCallback`: Optional callback function that will be invoked periodically with a progressInfo table with the overall progress (from 0 to 1). Type: `(progressInfo: { Progress: number }) -> ()`

Returns: A string generationId.

### GetBatchTokenDetailsAsync

```luau
AvatarCreationService:GetBatchTokenDetailsAsync(tokenIds: { any }): { any }
```

- Tags: Yields, Capabilities: Monetization

Gets the avatar creation token details for a list of avatar creation tokens at once.

Parameters:

- `tokenIds`: The list of avatar creation token IDs to get details of.

Returns: Array of avatar creation token details as outlined above.

### GetValidationRules

```luau
AvatarCreationService:GetValidationRules(): { [string]: any }
```

- Tags: Custom Lua state

Gets data regarding rules that assets must abide by to pass UGC validation.

Returns: Dictionary of validation rules as detailed above.

### HandleSelfieConsentResult

```luau
AvatarCreationService:HandleSelfieConsentResult(consentAccepted: boolean)
```

- Tags: Roblox script security

### HandleSelfieQRResult

```luau
AvatarCreationService:HandleSelfieQRResult(success: boolean, resultString: string)
```

- Tags: Roblox script security

### LoadAvatar2DPreviewAsync

```luau
AvatarCreationService:LoadAvatar2DPreviewAsync(previewId: string): EditableImage
```

- Tags: Yields, Capabilities: DynamicGeneration

Load an AvatarGeneration 2D preview on the client from a previewId.

Parameters:

- `previewId`: Load the preview generated from [`GenerateAvatar2DPreviewAsync()`](https://rapi.sleaze.dev/classes/AvatarCreationService.md).

Returns: An [`EditableImage`](https://rapi.sleaze.dev/classes/EditableImage.md) containing the preview image.

### LoadGeneratedAvatarAsync

```luau
AvatarCreationService:LoadGeneratedAvatarAsync(generationId: string): HumanoidDescription
```

- Tags: Yields, Capabilities: DynamicGeneration

Loads a generated avatar using an avatar generation ID.

Parameters:

- `generationId`: A unique string that identifies the generated avatar, as returned by [`AutoSetupAvatarAsync()`](https://rapi.sleaze.dev/classes/AvatarCreationService.md).

Returns: The [`HumanoidDescription`](https://rapi.sleaze.dev/classes/HumanoidDescription.md) of the generated avatar, which includes all the generated instances and properties.

### PrepareAvatarForPreviewAsync

```luau
AvatarCreationService:PrepareAvatarForPreviewAsync(humanoidModel: Model)
```

- Tags: Yields, Capabilities: AvatarAppearance

Prepares in-experience avatar for preview.

Parameters:

- `humanoidModel`: The [`Model`](https://rapi.sleaze.dev/classes/Model.md) containing [`MeshPart`](https://rapi.sleaze.dev/classes/MeshPart.md) children with [`WrapDeformer`](https://rapi.sleaze.dev/classes/WrapDeformer.md) instances that require HSR data updating for preview.

### PromptCreateAvatarAssetAsync

```luau
AvatarCreationService:PromptCreateAvatarAssetAsync(tokenId: string, player: Player, assetInstance: Instance, assetType: Enum.AvatarAssetType): ...any
```

- Tags: Yields

Prompts a [`Player`](https://rapi.sleaze.dev/classes/Player.md) to purchase and create an avatar asset from an [`Instance`](https://rapi.sleaze.dev/classes/Instance.md).

Parameters:

- `tokenId`: The ID of a creation token. The token must be valid in that the universe the method is called from is the same universe the token was created for. Furthermore, the token creator must maintain ID verification and [Roblox Premium](https://www.roblox.com/premium/membership). To create a token for utilization in this API, follow the [token creation](https://create.roblox.com/docs/production/monetization/avatar-creation-token) process. The token's creation type must match the `AvatarAssetType` passed in to the method.
- `player`: The [`Player`](https://rapi.sleaze.dev/classes/Player.md) intended to be presented with the creation prompt.
- `assetInstance`: The [`Instance`](https://rapi.sleaze.dev/classes/Instance.md) of the avatar asset intended for creation.
- `assetType`: The `AvatarAssetType` of the expected creation. This must match the creation type of the provided token.

Returns: A tuple containing, in order:

- An `PromptCreateAssetResult` indicating the result of the creation prompt.
- A string result. In the case of `PromptCreateAssetResult.Success`, this will indicate the asset ID. In the case of any failure enum, this will indicate the resultant error message.

### PromptCreateAvatarAsync

```luau
AvatarCreationService:PromptCreateAvatarAsync(tokenId: string, player: Player, humanoidDescription: HumanoidDescription): ...any
```

- Tags: Yields, Capabilities: AssetCreateUpdate + Monetization

Prompts a [`Player`](https://rapi.sleaze.dev/classes/Player.md) to purchase and create an avatar from a [`HumanoidDescription`](https://rapi.sleaze.dev/classes/HumanoidDescription.md).

Parameters:

- `tokenId`: The ID of an avatar creation token. The token must be valid in that the universe the method is called from is the same universe the token was created for. Furthermore, the token creator must maintain ID verification and [Roblox Premium](https://www.roblox.com/premium/membership). To create a token for utilization in this API, follow the [token creation](https://create.roblox.com/docs/production/monetization/avatar-creation-token) process.
- `player`: The [`Player`](https://rapi.sleaze.dev/classes/Player.md) intended to be presented with the creation prompt.
- `humanoidDescription`: The [`HumanoidDescription`](https://rapi.sleaze.dev/classes/HumanoidDescription.md) of the avatar intended for creation.

Returns: A tuple containing, in order:

- An `PromptCreateAvatarResult` indicating the result of the creation prompt.
- A string result. In the case of `PromptCreateAvatarResult.Success`, this will indicate the bundle ID. In the case of any failure enum, this will indicate the resultant error message.
- A secondary optional string result. In the case of `PromptCreateAvatarResult.Success`, this will indicate the outfit ID. In the case of any failure enum, this will be `nil`.

### PromptCreateMakeupAsync

```luau
AvatarCreationService:PromptCreateMakeupAsync(player: Player, makeupAssetEntries: { any }, thumbnailHeadColor: Color3? = nil): ...any
```

- Tags: Yields, Capabilities: AssetCreateUpdate + Monetization

### PromptSelectAvatarGenerationImageAsync

```luau
AvatarCreationService:PromptSelectAvatarGenerationImageAsync(player: Player): string
```

- Tags: Yields, Capabilities: SensitiveInput

Prompt the [`Player`](https://rapi.sleaze.dev/classes/Player.md) to take a selfie and return the FileId.

Parameters:

- `player`: The [`Player`](https://rapi.sleaze.dev/classes/Player.md) to prompt for taking a selfie.

Returns: A string FileId of the selfie on success, or an error string describing the reason for failure.

### RequestAvatarGenerationSessionAsync

```luau
AvatarCreationService:RequestAvatarGenerationSessionAsync(player: Player, callback: (...any) -> ...any): ...any
```

- Tags: Yields, Capabilities: DynamicGeneration

Request an AvatarGeneration session for a [`Player`](https://rapi.sleaze.dev/classes/Player.md).

Parameters:

- `player`: The [`Player`](https://rapi.sleaze.dev/classes/Player.md) to request an AvatarGeneration session for.
- `callback`: Callback function that is invoked with a SessionInfo table, with information about the session. Type: `(SessionInfo: { SessionId: string, Allowed2DGenerations: number, Allowed3DGenerations: number, SessionTime: number }) -> ()`

Returns: A tuple containing a [`RBXScriptConnection`](https://rapi.sleaze.dev/index/types/RBXScriptConnection.md) that can be used to cancel the session request and the estimated wait time in seconds.

### ValidateUGCAccessoryAsync

```luau
AvatarCreationService:ValidateUGCAccessoryAsync(player: Player, accessory: Instance, accessoryType: Enum.AccessoryType): ...any
```

- Tags: Yields

Studio only. Runs UGC validation for an `AccessoryType`.

Parameters:

- `player`: The [`Player`](https://rapi.sleaze.dev/classes/Player.md) validation is completed for.
- `accessory`: The instance validation is run on.
- `accessoryType`: The `AccessoryType` the instance is expected to be.

Returns: A tuple containing, in order:

- A boolean indicating if validation was successful for the accessory.
- An optional table of strings. This includes failure reasons if validation was unsuccessful; otherwise `nil` if validation was successful.

### ValidateUGCBodyPartAsync

```luau
AvatarCreationService:ValidateUGCBodyPartAsync(player: Player, instance: Instance, bodyPart: Enum.BodyPart): ...any
```

- Tags: Yields

Studio only. Runs UGC validation for an `BodyPart`.

Parameters:

- `player`: The [`Player`](https://rapi.sleaze.dev/classes/Player.md) validation is completed for.
- `instance`: The instance validation is run on.
- `bodyPart`: `BodyPart` the instance is expected to be.

Returns: A tuple containing, in order:

- A boolean indicating if validation was successful for the body part.
- An optional table of strings. This includes failure reasons if validation was unsuccessful; otherwise `nil` if validation was successful.

### ValidateUGCFullBodyAsync

```luau
AvatarCreationService:ValidateUGCFullBodyAsync(player: Player, humanoidDescription: HumanoidDescription): ...any
```

- Tags: Yields

Studio only. Runs UGC validation for a whole body.

Parameters:

- `player`: The [`Player`](https://rapi.sleaze.dev/classes/Player.md) validation is completed for.
- `humanoidDescription`: [`HumanoidDescription`](https://rapi.sleaze.dev/classes/HumanoidDescription.md) representing the body that validation is run on.

Returns: A tuple containing, in order:

- A boolean indicating if validation was successful for the body.
- An optional table of strings. This includes failure reasons if validation was unsuccessful; otherwise `nil` if validation was successful.

## Events

### AvatarAssetModerationCompleted

```luau
AvatarCreationService.AvatarAssetModerationCompleted: RBXScriptSignal<(assetId: number, moderationStatus: Enum.ModerationStatus)>
```

- Tags: Capabilities: DynamicGeneration

Fires when an in-experience-created avatar asset's moderation status has been updated from pending.

### AvatarModerationCompleted

```luau
AvatarCreationService.AvatarModerationCompleted: RBXScriptSignal<(outfitId: number, moderationStatus: Enum.ModerationStatus)>
```

- Tags: Capabilities: DynamicGeneration

Fires when an in-experience-created avatar's moderation status has been updated from pending.

### AvatarOutfitModerationCompleted

```luau
AvatarCreationService.AvatarOutfitModerationCompleted: RBXScriptSignal<(outfitId: number, moderationStatus: Enum.ModerationStatus, outfitType: Enum.OutfitType)>
```

- Tags: Capabilities: DynamicGeneration

Fires on the client when moderation completes for an in-experience-created outfit.

### OpenSelfieConsent

```luau
AvatarCreationService.OpenSelfieConsent: RBXScriptSignal<()>
```

- Tags: Roblox script security

### OpenSelfieQRCode

```luau
AvatarCreationService.OpenSelfieQRCode: RBXScriptSignal<(url: string, jobId: string)>
```

- Tags: Roblox script security

### ReplicateAvatarGenerationImageIdWithErrorType

```luau
AvatarCreationService.ReplicateAvatarGenerationImageIdWithErrorType: RBXScriptSignal<(fileId: string, errorType: number, errorMsg: string)>
```

- Tags: Hidden, Roblox engine security

### ReplicateAvatarModel

```luau
AvatarCreationService.ReplicateAvatarModel: RBXScriptSignal<(id: string, success: boolean, serializedModel: string, bufferTable: { [string]: any })>
```

- Tags: Hidden, Roblox engine security

### ReplicateAvatarPreviewUrl

```luau
AvatarCreationService.ReplicateAvatarPreviewUrl: RBXScriptSignal<(id: string, downloadUrl: string)>
```

- Tags: Hidden, Roblox engine security

### RequestAvatarGenerationImage

```luau
AvatarCreationService.RequestAvatarGenerationImage: RBXScriptSignal<()>
```

- Tags: Hidden, Roblox engine security

### RequestAvatarModel

```luau
AvatarCreationService.RequestAvatarModel: RBXScriptSignal<(id: string)>
```

- Tags: Hidden, Roblox engine security

### RequestAvatarPreviewUrl

```luau
AvatarCreationService.RequestAvatarPreviewUrl: RBXScriptSignal<(id: string)>
```

- Tags: Hidden, Roblox engine security

### UgcValidationFailure

```luau
AvatarCreationService.UgcValidationFailure: RBXScriptSignal<(guid: string, errorMessage: string)>
```

- Tags: Roblox script security

### UgcValidationSuccess

```luau
AvatarCreationService.UgcValidationSuccess: RBXScriptSignal<(guid: string, serializedModel: string, price: number)>
```

- Tags: Roblox script security

## Inherited members

- From [Instance](https://rapi.sleaze.dev/classes/Instance.md): `Archivable`, `archivable`, `Attributes`, `AttributesReplicate`, `AttributesSerialize`, `HistoryId`, `Name`, `Parent`, `PredictionMode`, `PropertyStatusStudio`, `RobloxLocked`, `SerializedOverrides`, `SourceAssetId`, `Tags`, `UniqueId`, `numExpectedDirectChildren`, `DataCost`, `Capabilities`, `DefinesCapabilities`, `IsInSandbox`, `Sandboxed`, `AddTag`, `ClearAllChildren`, `Clone`, `Destroy`, `FindFirstAncestor`, `FindFirstAncestorOfClass`, `FindFirstAncestorWhichIsA`, `FindFirstChild`, `FindFirstChildOfClass`, `FindFirstChildWhichIsA`, `FindFirstDescendant`, `GetActor`, `GetAttribute`, `GetAttributeChangedSignal`, `GetAttributes`, `GetChildren`, `GetDebugId`, `GetDescendants`, `GetFullName`, `GetStyled`, `GetStyledPropertyChangedSignal`, `GetTags`, `HasTag`, `IsAncestorOf`, `IsDescendantOf`, `IsPropertyModified`, `QueryDescendants`, `RemoveTag`, `ResetPropertyToDefault`, `SetAttribute`, `WaitForChild`, `Remove`, `children`, `clone`, `destroy`, `findFirstChild`, `getChildren`, `isDescendantOf`, `remove`, `AncestryChanged`, `AttributeChanged`, `ChildAdded`, `ChildRemoved`, `DescendantAdded`, `DescendantRemoving`, `Destroying`, `StyledPropertiesChanged`, `childAdded`
- From [Object](https://rapi.sleaze.dev/classes/Object.md): `ClassName`, `className`, `GetPropertyChangedSignal`, `IsA`, `isA`, `Changed`
