Skip to content

Color

Global · Color · server and client scripts

Color is an immutable linear RGBA color. Read R, G, B, and A, blend with :Lerp, adjust alpha with :WithAlpha, convert with :ToHSV and :ToHex, or build colors from linear channels, 0..255 RGB, hex strings, or HSV.

Example

-- Server script: tint a part orange with Color.fromRGB.
local part = World.Spawn({ Position = Vector3.Zero, Shape = "Box", Color = Color.White })
part.Color = Color.fromRGB(255, 136, 0)

new

Function
new(r: number, g: number, b: number, a: number?) -> Color

Color.new creates a color from non-negative linear r, g, b channels and an optional a alpha in [0, 1] (defaults to 1).

Example

-- Server script: create a bright HDR emissive color.
local glow = Color.new(2.5, 0.5, 0)
print(glow.R, glow.A)

fromRGB

Function
fromRGB(r: number, g: number, b: number, a: number?) -> Color

Color.fromRGB creates a color from r, g, b channels scaled by 255 and an optional a alpha in [0, 255] (defaults to 255).

Example

-- Server script: convert 0..255 RGB channels to a Color.
local accent = Color.fromRGB(64, 160, 255)
print(accent:ToHex())

fromHex

Function
fromHex(hex: string) -> Color

Color.fromHex parses a 6-digit or 8-digit hexadecimal color string, with or without a leading #.

Example

-- Server script: parse a hex color and fade its alpha.
local c = Color.fromHex("#ff8800"):WithAlpha(0.5)
print(c.A)

fromHSV

Function
fromHSV(hue: number, s: number, v: number, a: number?) -> Color

Color.fromHSV creates a color from hue in degrees, saturation s in [0, 1], non-negative value v, and optional alpha a in [0, 1].

Example

-- Server script: build a saturated green color from HSV.
local green = Color.fromHSV(120, 1, 1)
local h, s, v = green:ToHSV()
print(h, s, v)

White

PropertyRead only
White: Color

Color.White is opaque white (1, 1, 1, 1).

Default Color.new(1, 1, 1, 1)

Black

PropertyRead only
Black: Color

Color.Black is opaque black (0, 0, 0, 1).

Default Color.new(0, 0, 0, 1)

Transparent

PropertyRead only
Transparent: Color

Color.Transparent is transparent black (0, 0, 0, 0).

Default Color.new(0, 0, 0, 0)