Placed the color sequence keypoints in the right order, still errors?

I’m planning on showing the devforum my module, but it errors. Basically this line of code

local colorSequence = colorConverter.Convert({{0, Color3.fromRGB(255, 255, 255)}, {1, Color3.fromRGB(0, 0, 0)}}, "ColorSequence")

will work but THIS

local sequence2 = colorConverter.Convert({{0, Color3.fromRGB(0, 0, 0)}, {1, Color3.fromRGB(255, 255, 255)}}, "ColorSequence")

won’t work. Here’s the function responsible for this:

local function ifColorSequence(color, toConvert)
	if typeof(color) == "BrickColor" and toConvert == "ColorSequence" then
		local colorToConvert = color.Color
		local toReturn = ColorSequence.new(colorToConvert)
		return	toReturn
	elseif typeof(color) == "Color3" or typeof(color) == "ColorSequence" and toConvert == "ColorSequence" then
		local colorToConvert = color
		if typeof(color) == "Color3" then
			toReturn = ColorSequence.new(colorToConvert)
		end
		return toReturn
	elseif typeof(color) == "table" and toConvert == "ColorSequence" then
		for i, v in ipairs(color) do
			local colorSequenceKey = ColorSequenceKeypoint.new(v[1], v[2])
			table.insert(tableOfSequence, colorSequenceKey)
			print((tableOfSequence[i]).Time)
		end
		return ColorSequence.new(tableOfSequence)
	else
		error("Given invalid parameters")
	end
end

A convert function in the module calls this function, and the error says the keypoints should be in the correct order.

If it’s erroring then can you also actually tell us what the error is? Knowing what you’re getting in the console would be pretty helpful. If it’s just your “Given invalid parameters” error then you’ll want to review your conditionals since they aren’t passing but if it’s a different error then we need to know what it is.

1 Like

My younger brother is using the PC so I can’t access studio for an hour while he has coding classes, but it said something like “Keypoints should be in order.”

@colbert2677 just gave the error in this reply and in the original post.

Here’s the error:

 16:28:00.981  ColorSequence: all keypoints must be ordered by time  -  Server - ColorConverter:27

I already ordered it by time using ipairs, pcalling it tells me the script exhausted allowed execution time:

local returned
		repeat
		local success, toRETURN = pcall(function()
				returned = ColorSequence.new(tableOfSequence)
				task.wait(0.5)
			end)
		until success
		return returned

UPDATE: Somewhat fixed, a few print statements and some changes and everything seems to be working nicely, except this…

local sequence2 = colorConverter.Convert({{0, Color3.fromRGB(0, 0, 0)}, {0.25, Color3.fromRGB(255, 50, 50)}, {0.5, Color3.fromRGB(50, 255, 50)}, {0.75, Color3.fromRGB(50, 50, 255)}, {1, Color3.fromRGB(255, 255, 255)}}, "ColorSequence")

With a few print statements gives this:

16:51:27.666  0  -  Server - ColorConverter:25 --Time of keypoint
16:51:27.666  0.25  -  Server - ColorConverter:25 --Time of keypoint
16:51:27.666  0.5  -  Server - ColorConverter:25 --Time of keypoint

Doesn’t print 0.75 and 1

I have a few nitpicks.

In your second condition, the assignment of toReturn implies that toReturn is either an upvalue or some kind of global value, yet in the first it’s made a local variable. You also do not use it in your third condition. This also applies to tableofSequence.

The variable colorToConvert is unnecessary in both conditions.


These are my changes:

It appears that making tableOfSequence a local value for the ifColorSequence function is what helps you:
image

Although, next time, please modify your code to ensure that it isn’t filled with warnings and nil-value errors before asking. :^)

1 Like

Thanks for the help, although I need help with this one thing related to the module. When converting it to a color3 so that a part’s color can be compatible with the color sequence and turning the part’s color to the result of the conversion, the brick color is different from the color and manually setting the brick color in an attempt to force it won’t work. How would I fix this?
Reference:
Screenshot 2021-10-13 171715

Hello? @Fifkee are you still here? I have another problem related to the module.

Fell asleep.

There are ≈139 BrickColors versus the 16.7 million RGB values provide us. The best thing BrickColor can do is provide us the closest BrickColor an RGB value can represent.

1 Like