How can i lerp a colorsequence?

I tried lerping a colorsequence by doing:
script.Parent.Bar.UIGradient.Color = ColorSequence.new({ColorSequenceKeypoint.new(0, Color3.fromRGB(0,160,255)), ColorSequenceKeypoint.new(0.461, Color3.fromRGB(71,255,232)), ColorSequenceKeypoint.new(0.786, Color3.fromRGB(0,144,209)), ColorSequenceKeypoint.new(1, Color3.fromRGB(47,77,112))}):Lerp(ColorSequence.new({ColorSequenceKeypoint.new(0, Color3.fromRGB(255,140,0)), ColorSequenceKeypoint.new(0.461, Color3.fromRGB(255,220,0)), ColorSequenceKeypoint.new(0.786, Color3.fromRGB(255,130,0)), ColorSequenceKeypoint.new(1, Color3.fromRGB(112,77,47))}), stamina / 1)

but i got the error in output:

i dont know if i did anything wrong but it seems like roblox doesnt support it yet. is there a other way that i can actually lerp a colorsequence?
any help is appreciated

2 Likes

Isn’t a ColorSequence already a form of lerping?
Can you do a sequence in between the 1st and last one to change just the Keypoint0?

2 Likes

i dont know if you meant this because im new and couldnt fully understand what u said

script.Parent.Bar.UIGradient.Color = ColorSequence.new({ColorSequenceKeypoint.new(0, Color3.fromRGB(0,160,255)), ColorSequenceKeypoint.new(1, Color3.fromRGB(47,77,112))}):Lerp(ColorSequence.new({ColorSequenceKeypoint.new(0, Color3.fromRGB(255,140,0)),ColorSequenceKeypoint.new(1, Color3.fromRGB(112,77,47))}), stamina / 1.25)

still the same error

note: if i add a sequence to a lerp no matter what i get the same error

1 Like

What are you trying to change the ColorSequence for? A ParticleEmitter, a Trail, a Beam, or something else?

I don’t know if it’s possible to lerp it, but this may help: Color3 Lerp

You might be able to tween each one of the Color3 values at each of the 1st keypoints to the values of the 2nd keypoints.

You start with this:

keyframe  approximate color
0         cyan
.461      teal
.786      electric blue
1         storm blue

Then you want to change it to:

0         deep orange
.461      new yeller
.786      deep orange
1         earth orange

Honestly I’m not good enough with scripting to be able to help with it, but you or someone else might be able to figure it out.

1 Like

i trying to change it to make a stamina bar that if you sprint it gets oranger and more bluer if you release the sprint button but this seems impossible with sequences so i might switch to using single color3

note: i get error if i add sequences to tweens too

2 Likes

i wonder what you said there, , ,

2 Likes

Basically the same thing @Scottifly said. But I was not aware there was a Color3.new():Lerp() function :sweat_smile:

Devforum refuses to delete my post yet again! :rage:

1 Like

Well if you have 2 colour sequences with colours at the same time, you can just interpolate each of the colours individually, then reconstruct the colour sequence at the end. Something like this should work:

local function lerpColourSequence(a: ColorSequence, b: ColorSequence, t: number)
	local keypoints = {}
	
	for index, keypoint in a.Keypoints do
		local matchingKeypoint = b.Keypoints[index]
		
		if not matchingKeypoint then
			warn('ColourSequence can\'t be interpolated as there is no corresponding keypoint in `b`')
			
			return a
		end
		
		-- interpolate the colour
		table.insert(keypoints, ColorSequenceKeypoint.new(keypoint.Time, keypoint.Value:Lerp(matchingKeypoint.Value, t)))
	end
	
	return ColorSequence.new(keypoints)
end
2 Likes

could you give some tips about how can i implement this code? i didnt get like what do i have to put at where

note: this is what i have

ColorSequence.new({ColorSequenceKeypoint.new(0, Color3.fromRGB(0,160,255)), ColorSequenceKeypoint.new(0.461, Color3.fromRGB(71,255,232)), ColorSequenceKeypoint.new(0.786, Color3.fromRGB(0,144,209)), ColorSequenceKeypoint.new(1, Color3.fromRGB(47,77,112))}):Lerp(ColorSequence.new({ColorSequenceKeypoint.new(0, Color3.fromRGB(255,140,0)), ColorSequenceKeypoint.new(0.461, Color3.fromRGB(255,220,0)), ColorSequenceKeypoint.new(0.786, Color3.fromRGB(255,130,0)), ColorSequenceKeypoint.new(1, Color3.fromRGB(112,77,47))}), stamina / 1)
1 Like

You would just pass both colour sequences to the function, and a number indicating the percentage between a and b