Source: Roblox Creator Hub · CC BY 4.0 · View source · Code samples: MIT Imported 2026-10-03. Formatting adapted for this site.
ColorSequence
The ColorSequence data type represents a gradient of color values from 0 to 1. The color values are expressed using the ColorSequenceKeypoint type. This type is used in various properties of ParticleEmitter, Trail, Beam, and other objects that use color gradients.
Equality
Two ColorSequence objects are equivalent only if the values of their ColorSequenceKeypoint are equivalent, even if both would result in similar gradients.
Evaluation
The ColorSequence type does not have a built-in method for getting the value at a certain time/point. However, you can use the following function to evaluate at a specific time.
local function evalColorSequence(sequence: ColorSequence, time: number)
-- If time is 0 or 1, return the first or last value respectively
if time == 0 then
return sequence.Keypoints[1].Value
elseif time == 1 then
return sequence.Keypoints[#sequence.Keypoints].Value
end
-- Otherwise, step through each sequential pair of keypoints
for i = 1, #sequence.Keypoints - 1 do
local thisKeypoint = sequence.Keypoints[i]
local nextKeypoint = sequence.Keypoints[i + 1]
if time >= thisKeypoint.Time and time < nextKeypoint.Time then
-- Calculate how far alpha lies between the points
local alpha = (time - thisKeypoint.Time) / (nextKeypoint.Time - thisKeypoint.Time)
-- Evaluate the real value between the points using alpha
return Color3.new(
(nextKeypoint.Value.R - thisKeypoint.Value.R) * alpha + thisKeypoint.Value.R,
(nextKeypoint.Value.G - thisKeypoint.Value.G) * alpha + thisKeypoint.Value.G,
(nextKeypoint.Value.B - thisKeypoint.Value.B) * alpha + thisKeypoint.Value.B
)
end
end
end
local colorSequence = ColorSequence.new{
ColorSequenceKeypoint.new(0, Color3.fromRGB(255, 0, 0)),
ColorSequenceKeypoint.new(0.5, Color3.fromRGB(0, 190, 200)),
ColorSequenceKeypoint.new(1, Color3.fromRGB(190, 0, 255))
}
print(evalColorSequence(colorSequence, 0.75)) --> 0.372549, 0.372549, 0.892157 Constructors
| Name | Type / Returns | Description |
|---|---|---|
| ColorSequence.new | Returns a new ColorSequence that is entirely the specified color. | |
| ColorSequence.new | Returns a new ColorSequence with c0 as the start value and c1 as the end value. | |
| ColorSequence.new | Returns a new ColorSequence from an array of ColorSequenceKeypoints. |
ColorSequence.new
Returns a sequence of two keypoints with c for both the start and end values.
local colorSequence = ColorSequence.new(c)
-- Equivalent to
local colorSequence = ColorSequence.new{
ColorSequenceKeypoint.new(0, c),
ColorSequenceKeypoint.new(1, c)
} Parameters
| Name | Type | Default | Description |
|---|---|---|---|
| c | Color3 | The Color3 value used for both the start and end of the sequence. |
ColorSequence.new
Returns a new ColorSequence with c0 as the start value and c1 as the end value.
local colorSequence = ColorSequence.new(c0, c1)
-- Equivalent to
local colorSequence = ColorSequence.new{
ColorSequenceKeypoint.new(0, c0),
ColorSequenceKeypoint.new(1, c1)
} Parameters
| Name | Type | Default | Description |
|---|---|---|---|
| c0 | Color3 | The Color3 value at the start of the sequence (time 0). | |
| c1 | Color3 | The Color3 value at the end of the sequence (time 1). |
ColorSequence.new
Returns a new ColorSequence from an array of ColorSequenceKeypoints. The keypoints must be in a non-descending time value order. At least two keypoints must be provided, and they must have a time value of 0 (first) and 1 (last).
local red = Color3.fromRGB(255, 0, 0)
local cyan = Color3.fromRGB(0, 190, 200)
local purple = Color3.fromRGB(190, 0, 255)
local colorSequence = ColorSequence.new{
ColorSequenceKeypoint.new(0, red),
ColorSequenceKeypoint.new(0.5, cyan),
ColorSequenceKeypoint.new(1, purple)
} Parameters
| Name | Type | Default | Description |
|---|---|---|---|
| keypoints | Array | An array of ColorSequenceKeypoint values ordered by non-descending time, starting at time 0 and ending at time 1. Must contain at least 2 and no more than 20 keypoints. |
Properties
| Name | Type / Returns | Description |
|---|---|---|
| ColorSequence.Keypoints | Array | An array of ColorSequenceKeypoint values in ascending order. |
ColorSequence.Keypoints
An array containing ColorSequenceKeypoint values for the ColorSequence.
| Field | Value |
|---|---|
| type | Array |