So I have character customization in my game, and you can choose your skin color, but it does not work sometimes, When the player first joins, it works, but then after that it gives a different color, any reason why?
You should be using a BodyColors object to do this rather than overwriting the colour of every single limb. Not only is it more convenient to use in the way that it automatically applies colouring to limbs, but it also prevents colour overwriting if you have this in (limb colours eventually revert to BodyColors colors).
Chances are that CharacterAppearanceLoaded aren’t firing. Have you done debugging to confirm this? There’s no defined problem in the thread to address, just “this script doesn’t work and I have no idea why”. Doesn’t help much in terms of explanation or finding a source.
Same way you’re currently changing it but in terms of BodyColor properties. Here’s a code sample (meaning you aren’t meant to copy and paste it, rather to salvage and learn from it or break it apart and fit it into your code in a way you want).
-- Your table of colours here. You don't need to make a dictionary if you're
-- using numerical keys, just make a standard array. {color1, color2, ...}
-- note: spelling mistake with bunch? it says bucnh of color
local bucnhOfColor = {}
-- Put the colourable properties of BodyColors in a table for convenience
local BODY_COLORS = {"HeadColor", "TorsoColor", "LeftArmColor", "LeftLegColor", "RightArmColor", "RightLegColor"}
-- Check for existing BodyColors or create new one just in case
local bodyColors = character:FindFirstChild("Body Colors") or Instance.new("BodyColors")
-- Iterate over the previous colours table and set colours
for _, bodyColorPart in ipairs(BODY_COLORS) do
bodyColors[bodyColorPart] = BrickColor.new(bucnhOfColor[x])
end
-- Parent BodyColors if it has no parent (meaning it was created)
if not bodyColors.Parent then bodyColors.Parent = character end
local bucnhOfColor = {
[1] = "Pastel brown", --Default Shirt
[2] = "Neon orange", -- Army green
[3] = "Nougat", --Guess reckless
[4] = "Reddish brown", --Hawaiian shirt
}
game.Players.PlayerAdded:connect(function(player)
player.CharacterAppearanceLoaded:Connect(function(character)
local val = player:WaitForChild("stats"):WaitForChild("SkinColor").Value
wait(0.5)
if val >= #bucnhOfColor then
local BODY_COLORS = {"HeadColor", "TorsoColor", "LeftArmColor", "LeftLegColor", "RightArmColor", "RightLegColor"}
local bodyColors = character:FindFirstChild("Body Colors") or Instance.new("BodyColors")
for _, bodyColorPart in ipairs(BODY_COLORS) do
bodyColors[bodyColorPart] = BrickColor.new(bucnhOfColor[x])
end
if not bodyColors.Parent then bodyColors.Parent = character end
end
end)
end)
Naturally there’d be an error at x, because x isn’t a defined variable. That’s up to you to resolve by declaring x or replacing it with an appropriate value. A hint is that you do this exact thing in your old code.