Changing Player SkinColor based on Race Isn't working?

	if Data.SkinColor.Value == #Race.Orc.SkinColor then
		RaceAccessory.SkinColor(Character, 1)
	elseif Data.SkinColor.Value == #Race.Altmer.SkinColor then
		RaceAccessory.SkinColor(Character, 2)
	elseif Data.SkinColor.Value == #Race.Dunmer.SkinColor then
		RaceAccessory.SkinColor(Character, 3)
	elseif Data.SkinColor.Value == #Race.Bosmer.SkinColor then
		RaceAccessory.SkinColor(Character, 4)
	elseif Data.SkinColor.Value == #Race.Khajiit.SkinColor then
		RaceAccessory.SkinColor(Character, 5)
	elseif Data.SkinColor.Value == #Race.Argonian.SkinColor then
		RaceAccessory.SkinColor(Character, 6)
	elseif Data.SkinColor.Value == #Race.Vampire.SkinColor then
		RaceAccessory.SkinColor(Character, 7)
	end

So basically, what I’m aiming for is to change the player skincolor based on what race they are. So say they are an Orc race, so there would be 5 color options for them such as:

		SkinColor = {
			Color3.fromRGB(104, 113, 104),
			Color3.fromRGB(139, 168, 142),
			Color3.fromRGB(127, 142, 100),
			Color3.fromRGB(112, 129, 114),
			Color3.fromRGB(120, 144, 130)
		};

I’m also using Right and Left arrow key to make it so it turns there skincolor

		if v.Name == "ColorRightArrow" then
			if Player.CharacterData.SkinColor.Value < MaxSkinColor then
				Player.CharacterData.SkinColor.Value = Player.CharacterData.SkinColor.Value + 1
			end
		end
		
		if v.Name == "ColorLeftArrow" then
			if Player.CharacterData.SkinColor.Value > MinSkinColor then
				Player.CharacterData.SkinColor.Value = Player.CharacterData.SkinColor.Value - 1
			end
		end

Player.CharacterData.SkinColor:GetPropertyChangedSignal("Value"):Connect(function()
	if Player.CharacterData.SkinColor.Value < MaxSkinColor then
		RaceColor()
	end

	if Player.CharacterData.SkinColor.Value > MinSkinColor then
		RaceColor()
	end		
end)
1 Like

Iterate through the character’s body parts using a for loop and change their color

for i, v in ipairs(character:GetChildren()) do
	if v:IsA("BasePart") then
		v.Color = raceColor
	end
end
1 Like

Actually, not really the answer I’m looking for, but thank you for trying. I have that setup here:

module.SkinColor = function(Char, Number)
	if Number == RaceModule.Orc.Number then
		if Char:FindFirstChild("MeshPart" .. Data.SkinColor.Value) or Char:FindFirstChild("Part" .. Data.SkinColor.Value) == nil then
			for _, child in pairs(Char:GetChildren()) do
				if child.ClassName == "Part" or child.ClassName == "MeshPart" and child.BrickColor ~= BrickColor.new(Data.SkinColor.Value) then
					child.BrickColor = BrickColor.new(Data.SkinColor.Value)
				end

				if child.Name == "Orc" then
					child.OutsideEar.BrickColor = BrickColor.new(Data.SkinColor.Value)
					child.InsideEar.BrickColor = BrickColor.new(Data.SkinColor.Value)
				end
			end
		end
    end

Then what are you asking? You didn’t ask anything in the original post.

Sorry if my explanation wasn’t clear enough. So my end goal is to get it to work right? Because currently, it’s not working. So each race has there own specific colors right? And I used the orc (colors) as an example.

		SkinColor = {
			Color3.fromRGB(104, 113, 104),
			Color3.fromRGB(139, 168, 142),
			Color3.fromRGB(127, 142, 100),
			Color3.fromRGB(112, 129, 114),
			Color3.fromRGB(120, 144, 130)
		};

So what I’m trying to do is if Data.SkinColor.Value is 1, then it would skim through the colors shown above, does that make sense?

And that max number for colors is being 5, that is why I have this:

		if v.Name == "ColorRightArrow" then
			if Player.CharacterData.SkinColor.Value < MaxSkinColor then
				Player.CharacterData.SkinColor.Value = Player.CharacterData.SkinColor.Value + 1
			end
		end
		
		if v.Name == "ColorLeftArrow" then
			if Player.CharacterData.SkinColor.Value > MinSkinColor then
				Player.CharacterData.SkinColor.Value = Player.CharacterData.SkinColor.Value - 1
			end
		end

So the SkinColor table contains the color values to each race? How about having the index be the name for the race itself?

SkinColor = {
	["orc"] = color;
	["dunmer"] = color;
	etc...
}

Then you simply access it as such SkinColor[raceName]

Okay, so I’m doing this entirely wrong correct?

	if Data.SkinColor.Value == #Race.Orc.SkinColor then
		RaceAccessory.SkinColor(Character, 1)
	elseif Data.SkinColor.Value == #Race.Altmer.SkinColor then
		RaceAccessory.SkinColor(Character, 2)
	elseif Data.SkinColor.Value == #Race.Dunmer.SkinColor then
		RaceAccessory.SkinColor(Character, 3)
	elseif Data.SkinColor.Value == #Race.Bosmer.SkinColor then
		RaceAccessory.SkinColor(Character, 4)
	elseif Data.SkinColor.Value == #Race.Khajiit.SkinColor then
		RaceAccessory.SkinColor(Character, 5)
	elseif Data.SkinColor.Value == #Race.Argonian.SkinColor then
		RaceAccessory.SkinColor(Character, 6)
	elseif Data.SkinColor.Value == #Race.Vampire.SkinColor then
		RaceAccessory.SkinColor(Character, 7)
	end

Because the way I have them laid out is like this

	["Orc"] = {
		Name = "Ogfal",
		Description = "The Ogfal also known as big green dudes.",
		Number = 1,
		SkinColor = {
			Color3.fromRGB(104, 113, 104),
			Color3.fromRGB(139, 168, 142),
			Color3.fromRGB(127, 142, 100),
			Color3.fromRGB(112, 129, 114),
			Color3.fromRGB(120, 144, 130)
		};
	};

Ah, I think I see what you’re doing. You’re comparing Data.SkinColor.Value to the size of the SkinColor table, which is obviously wrong unless each SkinColor table has a different size.

If I may ask, what should I be doing that isn’t wrong?

You’re using the length of the skincolor table. If its the same for all of them, you’re always going to end up with the same value. You need to use whatever value you’re using to differentiate the races.

Okay, I have an understanding of what you mean. Now it’s just figuring out from here on why it’s doing this now.

https://i.gyazo.com/507f80fa9c052c371b883f0357231cde.mp4

By the way, this is how I setup the race skincolor table

I’ve finally solved it! Here’s what I did to solve the problem.

module.SkinColor = function(Char, Number)
	if Number == RaceModule.Orc.Number then
		if Char:FindFirstChild("MeshPart" .. Data.SkinColor.Value) or Char:FindFirstChild("Part" .. Data.SkinColor.Value) == nil then
			for _, child in pairs(Char:GetChildren()) do
				if child:IsA("BasePart") and child.Color ~= RaceModule.Orc.SkinColor[Data.SkinColor.Value] then
					child.Color = RaceModule.Orc.SkinColor[Data.SkinColor.Value]
				end

				if child.Name == "Orc" then
					child.OutsideEar.Color = RaceModule.Orc.SkinColor[Data.SkinColor.Value]
					child.InsideEar.Color = RaceModule.Orc.SkinColor[Data.SkinColor.Value]
				end
			end
		end
	end
end
1 Like

I know this is solved, but technically you could make use of variables so you don’t have to write an elseif chain. It’ll become very hard to read. Using variables to make this much shorter is not any less efficient than the elseif chain, rather just more practical.

1 Like

Thanks for your insight, I’ll be sure to implement this method in my scripting.