How do I mix colors in studio

i just learned how to find the average i now know what your saying

1 Like

this is giving me problems why is that when i place in colors

Can I see the error message please.

1 Like

its always turning black no matter the color
hers my code:

local function MixColors(Color1, Color2)

   local r = (Color1.R + Color2.R)/2

   local g = (Color1.G + Color2.G)/2

   local b = (Color1.B + Color2.B)/2

   return Color3.fromRGB(r,g,b)

end

workspace.Part0.Color = MixColors(workspace.Part1.Color, workspace.Part2.Color)

Here is some code I made that will allow you to add in a table of colors and return with the average of all the colors/the mix.

Please note that this only works with Color3.new() and nothing else.

function MixColors(colorTable)
	
	local colorRVal = 0
	local colorGVal = 0
	local colorBVal = 0
	
	local numR = 0
	local numG = 0
	local numB = 0
	
	for i = 1,#colorTable do
		local colorF = colorTable[i]
		colorRVal += colorF.R
		colorGVal += colorF.G
		colorBVal += colorF.B
		
		if colorF.R ~= 0 then
			numR += 1
		end
		
		if colorF.G ~= 0 then
			numG += 1
		end
		
		if colorF.B ~= 0 then
			numB += 1
		end
	end
	
	colorRVal = colorRVal / numR
	colorGVal = colorGVal / numG
	colorBVal = colorBVal / numB
	
	local newColor = Color3.new(colorRVal,colorGVal,colorBVal)
	
	return newColor
end

Implementing this is pretty easy.

First you want to do

local newColor = MixColors()

you can name this variable whatever you want,
Next add a table in-between the brackets.
EX.

local newColor = MixColors({
Color3.new(1,0,0),
Color3.new(0,1,0)
})

dose part.color work as Color3.new

I am sorry I misunderstood Color3 Values. This does work though, I tested it.

local function MixColors(Color1, Color2)
	local r = (Color1.R + Color2.R)* 127.5

	local g = (Color1.G + Color2.G) * 127.5

	local b = (Color1.B + Color2.B) * 127.5

	return Color3.fromRGB(r,g,b)

end
5 Likes

alright I will try this out tomorrow

1 Like

I tried it, when I input the value into a part it is black.
Please help.

Its been a year yk. Tommorow was a year ago