Convert a string to Color3.fromRGB?

Hi, so I have a string which is an RGB color:
“184, 7, 53”
It’s a string in a variable, how do I “convert” it into a Color3.fromRGB?

Use string.split(). Example:

local colorString = '123, 212, 96' -- your rgb
local colorStringSplitted = string.split(colorString, ', ')
local color = Color3.fromRGB(tonumber(colorStringSplitted[1]), tonumber(colorStringSplitted[2]), tonumber(colorStringSplitted[3]))
5 Likes

You could also use :match to optimize it for errors.

local color3 = "255, 240, 190"
local split = color3:split(",")
local concat = Color3.new(tonumber(split[1]:match("%d+"))/255, tonumber(split[2]:match("%d+"))/255, tonumber(split[3]:match("%d+"))/255)

I’d recommend using color3.new and dividing by 255 as it is Roblox’s intended use case.

3 Likes