How to convert Color3 value to a RGB value?

Is there a way to convert a Color3.new to a RGB value?
If so how?

2 Likes

Well since Color3 values can be numbers from 0-1, we can simply multiply their values by 255. (If that’s what you mean)

local C3 = Color3.new(.5, .5 , .5)
local RGB = Color3.fromRGB(C3.r*255, C3.g*255, C3.b*255)

(You can also simply use the Color3.fromRGB() function to create a color given its rgb values.)

2 Likes

it just gives me 0.5 ,0.5 ,0.5

2 Likes

Isn’t that what you want though? Now they both yield the same color.

If you want to actually read what the color is, you can do

local r, g, b = C3.R*255, C3.G*255, C3.B*255
2 Likes

The reason it’s not working is that you’re trying to pass non-whole numbers.

0.5*255 = 127.5.

Color3.fromRGB only accepts whole numbers.
To achieve that we need to use math.round:

local C3 = Color3.new(0.5,0.5,0.5)
local r, g, b = math.round(C3.R*255), math.round(C3.G*255), math.round(C3.B*255)
local RGB_Color = Color3.new(r,g,b)
5 Likes

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.