I am very new to scripting in general, and i’ve been trying to make a modulescript, CharacterCustomization, that holds race data for a bunch of races, which for now will simply be clothing and skin color.
This modulescript will be required by a script in serverscriptservice, which will apply a race to all players once they spawn. The modulescript is as follows:
local CharacterCustomization = {}
local raceData = {
Human = {
SkinColor = BrickColor.new("Beige"),
Shirt = "rbxassetid://73557102", -- Replace with actual asset IDs
Pants = "rbxassetid://73557125"
},
Aetherian = {
SkinColor = BrickColor.new("Bright blue"),
Shirt = "rbxassetid://2450222519",
Pants = "rbxassetid://2450196657"
},
Solari = {
SkinColor = BrickColor.new("Bright orange"),
Shirt = "rbxassetid://31107254",
Pants = "rbxassetid://635773681"
}
}
function CharacterCustomization.SetCharacterAppearance(character, race)
local data = raceData[race]
if data then
-- Wait for the Humanoid
local humanoid = character:WaitForChild("Humanoid")
local bodyColors = Instance.new("BodyColors", character)
-- Debugging output
print("Setting appearance for race: " .. race)
bodyColors.HeadColor = data.SkinColor
bodyColors.TorsoColor = data.SkinColor
bodyColors.LeftArmColor = data.SkinColor
bodyColors.RightArmColor = data.SkinColor
bodyColors.LeftLegColor = data.SkinColor
bodyColors.RightLegColor = data.SkinColor
for _, item in pairs(character:GetChildren()) do
if item:IsA("Shirt") or item:IsA("Pants") then
print("Removing clothing: " .. item.Name)
item:Destroy()
end
end
local shirt = Instance.new("Shirt", character)
shirt.ShirtTemplate = data.Shirt
print("Applied new shirt: " .. data.Shirt)
local pants = Instance.new("Pants", character)
pants.PantsTemplate = data.Pants
print("Applied new pants: " .. data.Pants)
else
warn("Race not found: " .. tostring(race))
end
end
return CharacterCustomization
The serverscript, RaceHandler, is as follows:
local ReplicatedStorage = game:GetService("ReplicatedStorage")
local CharacterCustomization = require(ReplicatedStorage:WaitForChild("CharacterCustomization"))
-- List of available races
local races = {"Human", "Aetherian", "Solari"}
-- Function to get a random race
local function getRandomRace()
return races[math.random(1, #races)]
end
game.Players.PlayerAdded:Connect(function(player)
player.CharacterAdded:Connect(function(character)
-- Wait for Humanoid to ensure it's loaded
character:WaitForChild("Humanoid")
-- Get a random race
local playerRace = getRandomRace()
-- Set character appearance based on the chosen race
CharacterCustomization.SetCharacterAppearance(character, playerRace)
end)
end)
(Please forgive the wonky patchup by ChatGPT, as i’ve tried to fix it using AI to no avail)
Whenever i have a player spawn, their clothing simply becomes invisible, and their skin color doesn’t change. Furthermore, explorer shows both the original clothing and new clothing, even though i’ve tried to delete them.
What errors am i making in these pieces of code? Thanks in advance.
