How to fix this color scroll wheel

Hello Developers,

I am trying to make a building system, so I want to make player choose part colors,so I am making a scroll now

How do I find which color is under the selection button, and how do I get its value in color3

If you are using an uigradient, you just need to find out which keypoints the selection button is between, and then interpolate between the colors of those keypoints.

-- selectionScalePos is a number between 0 and 1
-- telling where the selection button is on the color bar.
local function getColor(uiGradient, selectionScalePos)
	local colorKeyPoints = uiGradient.Color.KeyPoints
	for i = 2, #colorKeyPoints do
		local keyPoint = colorKeyPoints[i]
		local keyPos = keyPoint.Time
		if keyPos >= selectionScalePos then
			local previousKeyPoint = colorKeyPoints[i - 1]
			local previousPos = previousKeyPoint.Time
			
			local t = (selectionScalePos - previousPos) / (keyPos - previousPos)
			local color1, color2 = previousKeyPoint.Value, keyPoint.Value
			return Color3.new(color1.r * t + color2.r * (1 - t), color1.g * t + color2.g * (1 - t), color1.b * t + color2.b * (1 - t))
		end
	end
end
2 Likes

in getcolor function the second argument is mouse x and y position?

It’s a number between 0 and 1 telling where the black selection thing is on the scrollbar. So if the black thing is parented to the scroll bar and its position is set using scale, then the number is the x scale position of the black thing.

can you tell me what is the black thing here? and what is the time of a color? i mean color is not a timezone so what do you mean by time of color

I used time in the variable names just because the colorsequencekeypoint property is called ‘Time’. The ‘time’ variables aren’t really related to time at all. The Time property is a number between 0 and 1 and it actually tells the color’s position in the sequence, so I’ll change the variables to pos in the code.

And the black thing I was talking about is the thing that is near the beginning of the color bar in the picture and has a narrow white line in the middle. I thought it was something that is dragged when choosing the color, but maybe I was wrong.