Trouble changing keypoints on uigradient

Hi there! I’ve run into some trouble, I’m trying to change the 2 specific start and end Keypoints on a UIGradient, I have 2 color wheel pickers, in which I thought that taking 2 of them, and specifying the specific ends on each of them would work, it did not, here is the code for the first color picker,

	gradient.Color = ColorSequence.new{
		ColorSequenceKeypoint.new(0, hsv),
		ColorSequenceKeypoint.new(1, Color3.new(0, 0, 0))
	}

Here on the first one it’s changing the first point to the color being selected, and the second point its changing the color to black, but here on the second color picker

	gradient.Color = ColorSequence.new{
		ColorSequenceKeypoint.new(1, hsv),
	}

I’m trying to specify which end, but I got this error
Screenshot 2022-11-22 153454

So really i’m trying to have 2 separate color pickers, each changing the color of the points of the uigradient, and i’m having trouble getting the second color picker to change the color on the second point.

EDIT: Sorry if what I’m saying is confusing to read! I’m multitasking everywhere today

1 Like

Well as the error says, you only have 1 ColorSequenceKeypoint for the second color. If you want it to be a flat color (only 1 ColorSequenceKeypoint), then do ColorSequence.new(hsv) instead

1 Like

If I understand this correctly, you have two colour pickers that each affect one UiGradient where the first picker’s selected colour is the first end and the second picker’s colour would be the other end.

If you’re making a new ColorSequence and you’re using the constructor that takes an array of ColorSequenceKeypoints, you have to specify at least two ends. Since you only have two colours, you can use the constructor ColorSequence.new(c1, c2) where c1 and c2 are Color3’s.

Either you can have two variables that keep track of the selected colours and them update the gradient accordingly as either one of them changes:

-- These variables will hold the "hsv" variable for its respective picker
-- as they change, which you will have to update
local color1 = Color3.new() -- first colour picker's colour
local color2 = Color3.new() -- second colour picker's colour
-- When either of the colors are changed:
gradient.Color = ColorSequence.new(color1, color2)

Or you can reference the previous value of the other end and use that when you change either one of them:

-- As colour picker 1 is changed
gradient.Color = ColorSequence.new(
    hsv,
    gradient.Color.Keypoints[2].Value
)

-- As colour picker 2 is changed
gradient.Color = ColorSequence.new(
    gradient.Color.Keypoints[1].Value,
    hsv
)

You can refer to the ColorSequence docs by clicking this

3 Likes

ColorSequence takes an array of ColorSequenceKeypoints in ascending order, so you aren’t able to input Color3.new() like that

Ah thank you for this!!! I used your second bit of code, about referencing the previous value, and it worked like a charm! No errors or anything, I appreciate this!

ColorSequences do also have a constructor that takes in two Color3’s for the two ends, just like it can accept one flat Color3

ColorSequence | Roblox Creator Documentation

1 Like

Ahh got it, thanks!
I’ll be sure to look over the docs for Colorsequences

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.