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.
Download as DOCX, PDF, TXT or read online on Scribd
0 ratings0% 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.
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