How would you go about making an addition-subtraction button in RGBValues?

Confusing title, but not sure how else to concise it.


I’m trying to make an RGB picker, and to do that, I need to figure out how to use buttons to add/subtract 5 from R.Value.

As long as I get the base function of this script going, I can take care of everything else.

Thanks in advance.

1 Like

Hello,

Performing math equations with RGB values is a pain. But here’s one way you could do it:

function addOrSubtractColors(color1, color2, action)
	if action == "+" then
		return Color3.new(color1.r + color2.r, color1.g + color2.g, color1.b + color2.b)
	elseif action == "-" then
		return Color3.new(color1.r - color2.r, color1.g - color2.g, color1.b + color2.b)
	end
end

color1 in this case would be the original color.
color2 would be the color you want to add/subtract.

It’s pretty straight-forward and easy to understand.

Make sure color2 is a Color3.fromRGB() and not a Color3.new().

Hopefully this helps!

2 Likes

Personally I convert Color3 values into a Vector3 temporarily. (I might literally go make a feature request for color:ToVector() and Color3.fromVector now that I think about it)

Here’s what I do:

-- "Components," used to select specific colors easily
local rC = Vector3.new(1, 0, 0)/255
local gC = Vector3.new(0, 1, 0)/255
local bC = Vector3.new(0, 0, 1)/255
local color = Vector3.new(col3.r, col3.g, col3.b)

-- Example to add 5 to red:
color = color + rC * 5

-- Now we get the resulting Color3
col3 = Color3.new(color.x, color.y, color.z)

For the buttons you can use ClickDetectors.

Update: I did it Vector3 math for Color3 values

2 Likes