Color3

A data type representing an RGB color.

Unlike the standard Roblox API, this implementation of Color3 is mutable. You can change its R, G, and B components directly. Values will be automatically clamped to the valid 0.0 to 1.0 range.

local skyColor = Color3.new(0.5, 0.7, 1.0)
print(skyColor)

skyColor.R = 0 -- or "r", case doesn't matter
print(skyColor)

Constructor

Color3.new(r, g, b)

Creates a new Color3 object.

  • r: (Optional) number - Red component (0-1). Defaults to 1.0.

  • g: (Optional) number - Green component (0-1). Defaults to 1.0.

  • b: (Optional) number - Blue component (0-1). Defaults to 1.0.

Properties

Property

Type

Description

.R

number

(Read-Only) The red component of the color.

.G

number

(Read-Only) The green component of the color.

.B

number

(Read-Only) The blue component of the color.

local green = Color3.new(0, 1, 0)

Color3.fromRGB(r, g, b)

Creates a Color3 from components in the range 0 to 255.

  • r: (Optional) number - Red component (0-255). Defaults to 255.

  • g: (Optional) number - Green component (0-255). Defaults to 255.

  • b: (Optional) number - Blue component (0-255). Defaults to 255.

local red = Color3.fromRGB(255, 0, 0)
local dark_grey = Color3.fromRGB(50, 50, 50)

Color3.fromHSV(h, s, v)

Creates a Color3 from Hue, Saturation, and Value components (0-1).

  • h: number - Hue component (0-1).

  • s: number - Saturation component (0-1).

  • v: number - Value component (0-1).

local pink = Color3.fromHSV(0.9, 0.8, 1.0)

Color3.fromHex(hexString) Creates a Color3 from a hex color code string (e.g., "#FF00FF"). The leading # is optional.

  • hexString: string - The 6-digit hex code.

local purple = Color3.fromHex("#8A2BE2")

Properties

Property

Type

Description

Access

.R

number

The red component of the color (0-1).

Read/Write

.G

number

The green component of the color (0-1).

Read/Write

.B

number

The blue component of the color (0-1).

Read/Write


Methods

color:Lerp(goalColor3, alpha) -> Color3 Returns a new Color3 linearly interpolated between the two colors by alpha (0.0 to 1.0).

color:ToHSV() -> (h, s, v) Returns the Hue, Saturation, and Value of the color as three separate number values (0-1).

local c = Color3.fromRGB(255, 128, 0)
local h, s, v = c:ToHSV()
print(h, s, v)

color:ToHex() -> string Returns the 6-digit hex code string for the color, prefixed with #.

local c = Color3.new(1, 0, 1)
print(c:ToHex()) --> #FF00FF

Last updated