Using Hex colors in scripting

Hi, how would I use hex colors in script to change the color of a block or a mesh using hex numbers eg. # f1c27d

According to Developer Roblox site, you can use Color3.fromHex(string Hex) to convert Hex string to Color3 that you can use for anything that uses Color3.

If that doesn’t work you can use another method that I found online:

local function Hex2Color3(Hex: string): Color3
    Hex = Hex:gsub("#", "")
    return Color3.fromRGB(
        tonumber("0x" .. Hex:sub(1, 2)),
        tonumber("0x" .. Hex:sub(3, 4)),
        tonumber("0x" .. Hex:sub(5 ,6))
    )
end

local WhiteHex = "#FFFFFF"

-- works with or without "#" in front of the Hex code
local WhiteColor3 = Hex2Color3(WhiteHex)
1 Like