0% found this document useful (0 votes)
15 views

Avatar Customization Script

This document is a Lua script for customizing a player's avatar in a game, specifically for changing shirts, pants, hats, and heads using GUI buttons. It defines catalogs for each clothing type and includes functions to cycle through the available options when the corresponding buttons are clicked. The script ensures that the player character is correctly referenced and that existing items are managed appropriately during customization.
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
15 views

Avatar Customization Script

This document is a Lua script for customizing a player's avatar in a game, specifically for changing shirts, pants, hats, and heads using GUI buttons. It defines catalogs for each clothing type and includes functions to cycle through the available options when the corresponding buttons are clicked. The script ensures that the player character is correctly referenced and that existing items are managed appropriately during customization.
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 3

-- Avatar Customization Script

-- This script should be placed in the GUI Button handlers, or a LocalScript


inside the GUI.

local player = game.Players.LocalPlayer


local character = player.Character or player.CharacterAdded:Wait()
local humanoid = character:WaitForChild("Humanoid")

-- GUI Elements (Buttons)


local changeShirtButton = script.Parent:WaitForChild("ChangeShirtButton")
local changePantsButton =
script.Parent:WaitForChild("ChangePantsButton")
local changeHatButton = script.Parent:WaitForChild("ChangeHatButton")
local changeHeadButton =
script.Parent:WaitForChild("ChangeHeadButton")

-- Avatar parts to customize


local shirtCatalog = {"rbxassetid://123456789", "rbxassetid://987654321"}
-- Add shirt asset IDs
local pantsCatalog = {"rbxassetid://112233445", "rbxassetid://556677889"}
-- Add pants asset IDs
local hatCatalog = {"rbxassetid://667788990", "rbxassetid://112233445"} --
Add hat asset IDs
local headCatalog = {"rbxassetid://998877665", "rbxassetid://554433221"}
-- Add head asset IDs

local shirtIndex = 1
local pantsIndex = 1
local hatIndex = 1
local headIndex = 1

-- Function to change the player's shirt


local function changeShirt()
local shirt = character:FindFirstChildOfClass("Shirt") or
Instance.new("Shirt")
shirt.Parent = character
shirt.ShirtTemplate = shirtCatalog[shirtIndex]

-- Move to next shirt in catalog, loop around if out of range


shirtIndex = shirtIndex + 1
if shirtIndex > #shirtCatalog then
shirtIndex = 1
end
end
-- Function to change the player's pants
local function changePants()
local pants = character:FindFirstChildOfClass("Pants") or
Instance.new("Pants")
pants.Parent = character
pants.PantsTemplate = pantsCatalog[pantsIndex]

-- Move to next pants in catalog, loop around if out of range


pantsIndex = pantsIndex + 1
if pantsIndex > #pantsCatalog then
pantsIndex = 1
end
end

-- Function to change the player's hat


local function changeHat()
local existingHat = character:FindFirstChildOfClass("Accessory")
if existingHat then
existingHat:Destroy() -- Remove the existing hat
end

local hat = Instance.new("Accessory")


local hatPart = Instance.new("Part")
hatPart.Name = "Handle"
hatPart.Size = Vector3.new(1, 1, 1)
hatPart.Anchored = false
hatPart.CanCollide = false
hatPart.CFrame = character.Head.CFrame
hatPart.Parent = hat

hat.AttachmentPoint = Vector3.new(0, 0, 0)
hat.Parent = character

-- Set the hat texture (using catalog ID)


hat.TextureID = hatCatalog[hatIndex]

-- Move to next hat in catalog, loop around if out of range


hatIndex = hatIndex + 1
if hatIndex > #hatCatalog then
hatIndex = 1
end
end

-- Function to change the player's head


local function changeHead()
local newHead = Instance.new("Head")
newHead.Parent = character
newHead.MeshId = headCatalog[headIndex]

-- Move to next head in catalog, loop around if out of range


headIndex = headIndex + 1
if headIndex > #headCatalog then
headIndex = 1
end
end

-- Button Event Listeners


changeShirtButton.MouseButton1Click:Connect(changeShirt)
changePantsButton.MouseButton1Click:Connect(changePants)
changeHatButton.MouseButton1Click:Connect(changeHat)
changeHeadButton.MouseButton1Click:Connect(changeHead)

You might also like