Skip to content

No Color3 Constructor

ErrorAuto-fixableRoblox
small-rules/no-color3-constructor

Ban new Color3(...) except new Color3() or new Color3(0, 0, 0). Use Color3.fromRGB() instead.

Rationale

new Color3(r, g, b) takes floats from 0 to 1. Color3.fromRGB(r, g, b) takes 0 to 255. The float version is easier to get wrong and it’s slower. The engine converts internally. Just use fromRGB.

This bans new Color3(...) unless it’s new Color3() or new Color3(0, 0, 0). Those are fine. Auto-fixes the rest to fromRGB. If a component isn’t a literal number it’ll still flag it (set reportUnknownComponents to false if that bugs you).

Diagnostic Messages

onlyZeroArgs
Use Color3.fromRGB() instead of new Color3(). new Color3() uses floats [0-1] and performs worse than Color3.fromRGB() which uses [0-255]. Only 'new Color3()' or 'new Color3(0, 0, 0)' are allowed.
useFromRGB
Use Color3.fromRGB() instead of new Color3(). new Color3() uses floats [0-1] and performs worse than Color3.fromRGB() which uses [0-255].

Configuration

This rule accepts one options object after the severity.

reportUnknownComponentsOptional

Report new Color3(...) calls when one or more components are not numeric literals.

{
"jsPlugins": [
"@pobammer-ts/small-rules"
],
"rules": {
"small-rules/no-color3-constructor": [
"error",
{
"reportUnknownComponents": true
}
]
}
}

Examples

single-channel Color3 constructor
new Color3(255);

After auto-fix

Color3.fromRGB(255, 0, 0);
Color3 fromRGB factory
Color3.fromRGB(255, 128, 64);