How do I get R, G, and B values from ColorSequenceKeypoint? [New problem: Cannot convert Color3.new to Color3.fromRGB correctly]

I tried earlier, says r, g, and b are not valid members of ColorSequenceKeypoint:

local toAdd = Color3.fromRGB(0, 0, 0)
	for i, v in pairs(color.Keypoints) do
		toAdd = Color3.fromRGB(toAdd.r+(color.Keypoints[i][2].r), toAdd.g+(color.Keypoints[i][2].g), toAdd.b+(color.Keypoints[i][2].g))
	end
toAdd = Color3.fromRGB(toAdd.r/#color.Keypoints, toAdd.g/#color.Keypoints, toAdd.b/#color.Keypoints)

I looked for other solutions, some say look for just the keypoint, it said it was nil when I tried.

1 Like

ColorSequenceKeypoints come with a .Value that stores the Color3 in them. You can access each color by indexing R, G or B.

3 Likes

I felt a bit stupid after reading this. Thanks

1 Like

EDIT: When printing, the value of the color3 has gone ABSURD:

9.49606e-07, 3.21944e-06, 3.84318e-06

How would I fix this?
Meant to reply to @happygeneral2015

Could you send the full code so that I can see it for myself?

local function ifColor3(color, toConvert)
	if typeof(color) == "BrickColor" and toConvert == "Color3" then
		local colorToConvert = color.Color
		return	colorToConvert
	elseif typeof(color) == "ColorSequence" and toConvert == "Color3" then
		local toAdd = Color3.fromRGB(0, 0, 0)
		for i, v in pairs(color.Keypoints) do
			toAdd = Color3.fromRGB(toAdd.r+(v.Value.r), toAdd.g+(v.Value.g), toAdd.b+(v.Value.b))
		end
		toAdd = Color3.fromRGB(toAdd.r/#color.Keypoints, toAdd.g/#color.Keypoints, toAdd.b/#color.Keypoints)
		return toAdd
	elseif typeof(color) == "table" and toConvert == "Color3" then
		
	end
end

This is just the function

I should have mentioned. The R, G and B returned are in the Color3.new format. To actually get the RGB that ranges from 0 - 255, you will need to convert it.

1 Like

How would I convert them? Should I just multiply it by 255 or something?

1 Like

Yes simply multiply by 255. If you need any more help, let me know.
I have no clue why Roblox thought it was a good idea to have the default colour range from 0 to 1. Odd design decisions that we will never know haha

2 Likes

It still seems to be a Color3.new format. Also, am I getting the average correctly?

local toAdd = Color3.fromRGB(0, 0, 0)
		for i, v in pairs(color.Keypoints) do
			print(v.Value)
			toAdd = Color3.fromRGB(toAdd.r+(v.Value.r*255), toAdd.g+(v.Value.g*255), toAdd.b+(v.Value.b*255))
		end
		toAdd = Color3.fromRGB(((toAdd.r)/#color.Keypoints), ((toAdd.g)/#color.Keypoints), ((toAdd.b)/#color.Keypoints))
		return toAdd

Still gives a value lower than 1, far, far lower, here’s the final Color3 value (Total)

0.000242149, 0.000820956, 0.000980011 

EDIT: Hello? @happygeneral2015 are you there>

Probably a has to do with floating point and zero.

You can see the numbers are all very small however Roblox doesn’t seem to understand the difference between a very small number and 0.

(Just treat numbers that have a e-<number> as 0 and e<number> as very large)

1 Like

I already know this, I’m just asking if I have converted it correctly because it’s still so small and acting like it’s still color3.new instead of fromRGB

I think it should be fine. As I said I think the reason why that happens might be because you are inputting 0. It could be that you don’t have an actual value in the Color3Value.

What value do you have in your Color3Value?

1 Like

Color3Value? I don’t have a color3 value anywhere, @happygeneral2015 told me that ColorSequenceKeypoints have a .Value for the Color3 stored in it

Sorry for not responding. Didn’t see your message.

local white = Color3.new(1, 1, 1)
local lightBlue = Color3.new(0, 2/3, 1)
local yellow = Color3.new(1, 1, 0)

local myColor = ColorSequence.new{
    ColorSequenceKeypoint.new(0, white),
    ColorSequenceKeypoint.new(0.25, lightBlue),
    ColorSequenceKeypoint.new(0.5, white),
    ColorSequenceKeypoint.new(0.75, yellow),
    ColorSequenceKeypoint.new(1, white)
}

local function ifColor3(color, toConvert)
    if typeof(color) == "BrickColor" and toConvert == "Color3" then
        local colorToConvert = color.Color;
        return colorToConvert;
    elseif typeof(color) == "ColorSequence" and toConvert == "Color3" then
        local startColor = Color3.new(0, 0, 0);
        for i,v in pairs(color.Keypoints) do
            startColor = Color3.new(startColor.R + v.Value.R, startColor.G + v.Value.G, startColor.B + v.Value.B)
        end
        return Color3.fromRGB(startColor.R * 255 / #color.Keypoints, 
            startColor.G * 255 / #color.Keypoints, 
            startColor.B * 255 / #color.Keypoints);
    elseif typeof(color) == "table" and toConvert == "Color3" then
        return Color3.fromRGB(color[1], color[2], color[3]);
    end
end

print(ifColor3(myColor, "Color3"));
warn(string.rep("-", 50));
2 Likes

Wasn’t able to see your message as well, I’ll try out your solution and see if it works

It’s still in the Color3.new format, but I guess it’s fine for now.