Color3 Expected got string

I am getting an error where it’s getting a string instead of color3, how would I fix this?

Script
local TakenColors = {}

local AvailableColors = {
	"1, 0.686275, 0.882353",
	"0.552941, 0.219608, 0.219608",
	"1, 0.34902, 0.34902",
	"1, 0.686275, 0.431373",
	"0.992157, 0.917647, 0.552941",
	"0.156863, 0.498039, 0.278431",
	"0.541176, 0.670588, 0.521569",
	"0.501961, 0.733333, 0.858824",
	"0.0509804, 0.411765, 0.67451",
	"0.54902, 0.356863, 0.623529",
	"0.490196, 0.494118, 0.52549",
	"0.105882, 0.164706, 0.207843",
	"0.533333, 0.431373, 0.368627",
	"0.337255, 0.258824, 0.211765"
}

game:GetService("Players").PlayerAdded:Connect(function(Player)
	Player.CharacterAdded:Connect(function(Character)
local function PickColor()
		local ChosenColor = AvailableColors[math.random(1,AvailableColors)]
			if not table.find(TakenColors, ChosenColor) then
				table.insert(TakenColors, ChosenColor)
				Character["Body Colors"].TorsoColor3 = ChosenColor
				Character["Body Colors"].LeftLegColor3 = ChosenColor
				Character["Body Colors"].RightLegColor3 = ChosenColor
			else
				PickColor()
			end
		end
		PickColor()
	end)
end)
1 Like

Those are strings in a table, not numbers

Rmove the " and they will become numbers

3 Likes

Im getting a new error which is saying got table number expected. At the math.random line. Do you know how to fix? Should I use tostring?

1 Like

try [math.random(1,#AvailableColors)]

2 Likes

It says it got table instead of number

1 Like

Since you have strings in a table and I imagine that you want the numbers to be picked together, you should do:

Character["Body Colors"].TorsoColor3 = tonumber(ChosenColor)
Character["Body Colors"].LeftLegColor3 = tonumber(ChosenColor)
Character["Body Colors"].RightLegColor3 = tonumber(ChosenColor)
3 Likes

ah yes. I forgot tonumber is a thing

2 Likes

Thank you! But it says got number table expected? Might have fixed it I did
Color3.new(tonumber(ChosenColor))

1 Like

Oh right, try:

Character["Body Colors"].TorsoColor3 = Color3.new(tonumber(ChosenColor))
Character["Body Colors"].LeftLegColor3 = Color3.new(tonumber(ChosenColor))
Character["Body Colors"].RightLegColor3 = Color3.new(tonumber(ChosenColor))
2 Likes

Strange its saying table expected and got number… for the math.random part

1 Like

have you tried:

local ChosenColor = AvailableColors[math.random(1,#AvailableColors)]
2 Likes

It finally has Worked! Thank you, I would give you a solution if it was the main purpose of the post. I really appreciate you

2 Likes

Although I would use this instead of your color table as it would always return nil for the chosen color:

local AvailableColors = {
	1 ..", ".. 0.686275 ..", "..0.882353,
	0.552941 ..", ".. 0.219608 ..", ".. 0.219608,
	1 ..", ".. 0.34902 ..", ".. 0.34902,
	1 ..", ".. 0.686275 ..", ".. 0.431373,
	0.992157 ..", ".. 0.917647 ..", ".. 0.552941,
	0.156863 ..", ".. 0.498039 ..", ".. 0.278431,
	0.541176 ..", ".. 0.670588 ..", ".. 0.521569,
	0.501961 ..", ".. 0.733333 ..", ".. 0.858824,
	0.0509804 ..", ".. 0.411765 ..", ".. 0.67451,
	0.54902 ..", ".. 0.356863 ..", ".. 0.623529,
	0.490196 ..", ".. 0.494118 ..", ".. 0.52549,
	0.105882 ..", ".. 0.164706 ..", ".. 0.207843,
	0.533333 ..", ".. 0.431373 ..", ".. 0.368627,
	0.337255 ..", ".. 0.258824 ..", ".. 0.211765
}
1 Like

You also don’t have to use tonumber() for the Color3.new() if you use this anymore.

1 Like

For some reason the body colors end up not being the color it is, its always 1254, 0, 0

Yeah, sorry about that, I had it all wrong. Use this:

local AvailableColors = {
	Color3.new(1, 0.686275, 0.882353),
	Color3.new(0.552941, 0.219608, 0.219608),
	Color3.new(1, 0.34902, 0.34902),
	Color3.new(1, 0.686275, 0.431373),
	Color3.new(0.992157, 0.917647, 0.552941),
	Color3.new(0.156863, 0.498039, 0.278431),
	Color3.new(0.541176, 0.670588, 0.521569),
	Color3.new(0.501961, 0.733333, 0.858824),
	Color3.new(0.0509804, 0.411765, 0.67451),
	Color3.new(0.54902, 0.356863, 0.623529),
	Color3.new(0.490196, 0.494118, 0.52549),
	Color3.new(0.105882, 0.164706, 0.207843),
	Color3.new(0.533333, 0.431373, 0.368627),
	Color3.new(0.337255, 0.258824, 0.211765)
}

(don’t use tonumber())

1 Like