Avatar | Humanoid Description Extension!

Description By ChatGpt:


Module Overview

This module enables comprehensive avatar customization in Roblox, including clothing, body parts, colors, and animations.

Custom Types

  1. Avatar: Represents an avatar with a Humanoid and HumanoidDescription.

    type Avatar = {
        Humanoid: Humanoid,
        Description: HumanoidDescription
    }
    
  2. Ids: A list of numerical asset IDs.

    type Ids = {number}
    
  3. WearList: Clothing/accessory items with asset IDs and types.

    type WearList = {{AssetId: number, AccessoryType: Enum.AccessoryType}}
    
  4. ClassicData: Holds classic clothing asset IDs.

    type ClassicData = {GraphicTShirt: number, Pants: number, Shirt: number}
    
  5. BodyColorData: Mapping of body part color types to colors.

    type BodyColorData = {[BodyColors]: Color3 | BrickColor}
    
  6. ScaleData: Mapping of scale attributes to values.

    type ScaleData = {[Scales]: number}
    
  7. Serial: Structured data for serialization.

    type Serial = {ClassicData: ClassicData, WoreList: WearList, BodyData: BodyData, BodyColorData: BodyColorData, ScaleData: ScaleData, AnimData: AnimData}
    

Module Functions

module.new(Humanoid: Humanoid)

Creates a new Avatar instance.

Example:

local myAvatar = module.new(game.Players.LocalPlayer.Character:WaitForChild("Humanoid"))

module.Create(Serial: Serial)

Creates an avatar from a template and optionally unserializes data.

Example:

local myAvatar, template = module.Create(existingSerial)

Avatar:CoverBody()

Ensures the avatar’s body is covered with default clothing if script.CoverBody is set to true. If script.CoverBody is false, this method has no effect.

Example:

myAvatar:CoverBody()

Avatar:Apply()

Applies the current HumanoidDescription to the Humanoid. No modifications will take effect until this method is called.

Example:

myAvatar:Apply()

Avatar:Reset()

Resets the avatar’s appearance to match the HumanoidDescription of the template.

Example:

myAvatar:Reset()

Avatar:Wear(WearIds: Ids)

Wears accessories or classic clothing based on specified asset IDs, automatically determining the type/property for each ID. Returns a list of failed IDs.

Example:

local failedIds = myAvatar:Wear({123456789, 987654321})

Avatar:Classic(WearIds: Ids)

Applies classic clothing based on the specified asset IDs, automatically determining the type/property. It only uses classic clothing asset IDs and is a slightly faster method than Wear. Returns a list of failed IDs.

Example:

local failedIds = myAvatar:Classic({1111111111, 2222222222})

Avatar:SetClassic(ClassicData: ClassicData)

Sets classic clothing items based on provided data. Requires manual input for each clothing type.

Example:

myAvatar:SetClassic({GraphicTShirt = 123456789, Pants = 987654321, Shirt = 1122334455})

Avatar:TakeOff(RemoveIds: Ids)

Removes specified clothing or accessories, including classic clothing asset IDs.

Example:

myAvatar:TakeOff({123456789, 1111111111}) -- Removes specified classic clothing and accessories

Avatar:RemoveAll()

Removes all accessories and clothing from the avatar.

Example:

myAvatar:RemoveAll()

Avatar:GetWearIds()

Retrieves the current asset IDs of worn items.

Example:

local currentWearIds = myAvatar:GetWearIds()

Avatar:SetClothing(WearList: WearList | LayeredList)

Sets clothing from a provided list of accessories.

Example:

myAvatar:SetClothing({{AssetId = 123456789, AccessoryType = Enum.AccessoryType.Shirt}})

Avatar:Paint(BodyColorsData: BodyColorData)

Paints the avatar’s body parts with specified colors.

Example:

myAvatar:Paint({HeadColor = Color3.new(1, 0, 0)}) -- Paints head red

Avatar:PaintAll(Color: BrickColor | Color3)

Paints all body parts with the same color.

Example:

myAvatar:PaintAll(BrickColor.new("Bright blue"))

Avatar:Scale(Scales: ScaleData)

Sets the scale for various body parts. Requires manual input for each scale type.

Example:

myAvatar:Scale({HeightScale = 1.5, WidthScale = 1.2})

Avatar:Body(BundleIds: Ids)

Sets the avatar’s body parts based on specified bundle IDs, automatically determining the body part type. Returns a list of failed IDs.

Example:

local failedBundles = myAvatar:Body({123456789, 987654321})

Avatar:BodyPart(BodyPartIds: Ids)

Sets specific body parts based on provided IDs, automatically determining the body part type. Returns a list of failed IDs.

Example:

local failedParts = myAvatar:BodyPart({123456, 654321})

Avatar:SetBodyPart(BodyData: BodyData)

Sets body part IDs from the provided data, requiring explicit mapping of each part type.

Example:

myAvatar:SetBodyPart({Head = 123456789, Torso = 987654321})

Avatar:GetBodyPart()

Retrieves the current body part IDs.

Returns:

  • A table mapping body part types to their asset IDs.

Example:

local bodyParts = myAvatar:GetBodyPart()

Avatar:GetColor()

Retrieves the current body part colors.

Returns:

  • A table mapping body part colors to their respective values.

Example:

local colors = myAvatar:GetColor()

Avatar:GetScale()

Retrieves the current scale values for the avatar.

Returns:

  • A table mapping scale types to their respective values.

Example:

local scales = myAvatar:GetScale()

Avatar:GetClassic()

Retrieves the current classic clothing IDs.

Returns:

  • A table mapping classic clothing types to their asset IDs.

Example:

local classicItems = myAvatar:GetClassic()

Avatar:GetAnimation()

Retrieves the current animation IDs.

Returns:

  • A table mapping animation types to their asset IDs.

Example:

local animations = myAvatar:GetAnimation()

Avatar:Animate(BundleIds: Ids)

Sets animations for the avatar based on specified bundle IDs, automatically determining the animation type. Returns a list of failed IDs.

Example:

local failedAnimations = myAvatar:Animate({123456789, 987654321})

Avatar:Animation(AnimationIds: Ids)

Sets specific animations using their asset IDs, requiring explicit mapping of animation types. Returns a list of failed IDs.

Example:

local failedAnimations = myAvatar:Animation({123456789, 987654321})

Avatar:SetAnimation(AnimData: AnimData)

Sets multiple animations at once from provided data, requiring explicit mapping of each animation type.

Example:

myAvatar:SetAnimation({IdleAnimation = 123456, WalkAnimation = 789012})

Avatar:Serialize()

Serializes the avatar’s current state into a structured format.

Returns:

  • A table containing serialized avatar data.

Example:

local serializedData = myAvatar:Serialize()

Avatar:Unserialize(Serial)

Applies serialized data to the avatar.

Example:

myAvatar:Unserialize(serializedData)

Avatar:Destroy()

Cleans up the Avatar instance by clearing its data and removing its metatable. This makes the instance eligible for garbage collection.

Example:

myAvatar:Destroy()

Conclusion

This module provides an efficient way to customize avatars in Roblox, covering clothing, body parts, colors, and animations through a structured API. Each function is designed for specific tasks, making integration straightforward for any game. Modifications will not take effect until the Apply method is called, and the Destroy method helps manage memory by cleaning up the instance when it’s no longer needed.


Here is the Avatar Module:
Avatar.rbxm (35.3 KB)

5 Likes