Avatar is a module script that extend functionality of the Humanoid Description system
Get It Here: Avatar - Creator Store
Version 1.31
Basic Example:
local Avatar = require(PathToAvatar)
local Guy, Rig = Avatar.Create() -- This create a new Template Rig
-- Alternatively you can use Avatar.new(YourRig's Humanoid)
-- By changing the Template under the module, Create will return a different Rig according to that Template
Guy:Wear({123, 456, 789}) -- Fictional Ids
-- Wear will add ClothingIds into the Humanoid Description of the Avatar Object
-- Format: {ClothingId}
-- ClothingId can be either a AccessoryId, LayeredClothingId, or 2DClothingId(Shirt, Pants, Tshirt)
Guy:Body({100, 200, 300})
-- Body will add all Items in the BundleIds into the Humanoid Description of the Avatar Object
-- Will be placed into BodyPart Categories accordingly based on BodyPartType
-- Format: {BundleId}
-- If a Clothing is part of the Bundle, Wear will be called on that ItemId
Guy:Animate({111, 222, 333})
-- Animate will add all Items in the BundleIds into the Humanoid Description of the Avatar Object
-- Will be placed into different Animation Categories accordingly based on AnimType
-- Format: {BundleId}
Guy:PaintAll(BrickColor.Random())
-- Set all BodyParts' Color to given Color
-- Format: Color3 | BrickColor
Guy:Paint({TorsoColor = BrickColor.Random()})
-- Set specified BodyParts' Color to given Color
-- Format: {BodyColorName : Color3 | BrickColor}
Guy:TakeOff({123})
-- TakeOff will remove all listed ClothingIds from the Humanoid Description
-- If given Ids not found then it does nothing
Guy:RemoveAll()
-- Set Clothings of the Humanoid Description to {} O_O
Guy:Apply()
-- All changes will only be applied when Apply is called
-- By default CoverBody boolean value under the module is set to true
-- It will automatically cover the Rig with basic 2D Shirt and Pants when Apply is called
Guy:Destroy()
-- Destroy the Avatar Object
-- Do this when you don't need it anymore
Advanced
Description By ChatGpt:
Module Overview
This module enables comprehensive avatar customization in Roblox, including clothing, body parts, colors, and animations.
Custom Types
-
Avatar: Represents an avatar with a
Humanoid
andHumanoidDescription
.type Avatar = { Humanoid: Humanoid, Description: HumanoidDescription }
-
Ids: A list of numerical asset IDs.
type Ids = {number}
-
WearList: Clothing/accessory items with asset IDs and types.
type WearList = {{AssetId: number, AccessoryType: Enum.AccessoryType}}
-
ClassicData: Holds classic clothing asset IDs.
type ClassicData = {GraphicTShirt: number, Pants: number, Shirt: number}
-
BodyColorData: Mapping of body part color types to colors.
type BodyColorData = {[BodyColors]: Color3 | BrickColor}
-
ScaleData: Mapping of scale attributes to values.
type ScaleData = {[Scales]: number}
-
Serial: Structured data for serialization.
type Serial = {ClassicData: ClassicData, WoreList: WearList, BodyData: BodyData, BodyColorData: BodyColorData, ScaleData: ScaleData, AnimData: AnimData}
-
ClothType: Combination of AssetTypes relevant to Clothing.
type ClothType = Enum.AccessoryType | "Shirt" | "Pants" | "TShirt"
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, Reverse: boolean)
Removes specified clothing or accessories, including classic clothing asset IDs, Reverse will takeoff all clothing related items except those with id that’s listed in the RemoveIds. Return a list of failed IDs.
Example:
local failedIds = myAvatar:TakeOff({123456789, 1111111111}) -- Removes specified classic clothing and accessories
Avatar:RemoveAll(Exclude: {ClothType})
Removes all accessories and clothing from the avatar, Exclude parameter will prevent removal of all items that has the specified ClothType.
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, automatically determining the animation type. 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.