How to convert color sequence to a table value (how to read colors in a colorsequence, kinda)

How to read the colors in a ColorSequence? (This post is not the same question)

Bascially, I have made a lot of different color sequences for my game, but I would like to be able to “save these” in a script/datastore.

So how would I get the table from the below values:

I know how to construct a color sequence with a script, but I would like to do it the other way around. It seems very tedious to make dozens of color sequences with scripts. Instead, I’d love to get the values in the table.

Hope you get what I mean.

(@Nappinz it seemed like you knew a lot about color sequences?)

IN SHORT:
How to go from this:


to this:

colortable = {ColorSequenceKeypoint.new(0,Color3.new(0,0,0)),ColorSequenceKeypoint.new(0.1, Color3.new(1,1,1)), ColorSequenceKeypoint.new(1, Color3.new(0.5,0.3,1))}

Edit: I tried this:
tableValues = script.Parent.ParticleEmitter.Color.Keypoints

for i, v in pairs(tableValues) do

print(v)

end

But it outputs very strange stuff.

All you really need to do to get the table that constructs the color sequence is “ColorSequence.Keypoints”. However when you print this value it will not show because Roblox has not made “ColorSequenceKeypoint” a printable object.

If you’re looking to print the table that constructs a color sequence you can convert the values the “ColorSequenceKeypoint” holds - something like this:

local function ColorSequenceToTable(colorSequence)
	local t = {}
	local keypoints = colorSequence.Keypoints
	for i, keypoint in ipairs(keypoints) do
		t[i] = {
			Time = keypoint.Time;
			Value = keypoint.Value;
		}
	end
	
	return t
end

And if you want to convert the printable table back into a table that constructs a ColorSequence, you can do something like this:

local function TableToColorSequence(t)
	local construct = {}
	for i, info in ipairs(t) do
		construct[i] = ColorSequenceKeypoint.new(info.Time, info.Value)
	end
	
	return ColorSequence.new(construct)
end
4 Likes

Hey, thanks for the answer! I tested it out, but it get some strange output, I get 1 time value and then 3 color values separated by commas. But the comma values don’t correspond with the RGB value set AT ALL.

The one color:
0.901961, 0.803922, 0.941176 is supposed to be: 255, 58, 78

But, the interesting part is:
White which is (255, 255, 255) is (from the table value) 1,1,1.

That had me thinking, Oh, it’s just divided by 255. But no. It was not.

Is there something I am not seeing here? Is it divided by something, or is it a different color scheme. (Like decimals, where 1 is a full value?)

Thanks.

It should just be divided by 255, I think you may be mixing up the colors. If you aren’t then I honestly don’t know the reason.

Color3 values can be multiple types, RGB = 0 - 255 where Color3.new() = 0,1 (written in decimal 0 = 0 and 1 = 255)

1 Like