Make color3 darker via script?

I want to make a darker version of my Color3. For some reason this doesn’t work:

function darken(color, amount)
    return Color3.fromRGB(color.r - amount, color.g - amount, color.b - amount)
end

It always returns 0,0,0?

I’m assuming amount here is a value between 0 and 255?

The r, g and b properties are values between 0 and 1 if I recall correctly. the fromRGB() method however uses ranges between 0 and 255. This means the values you’re passing will be no more than 1, which is really black. I think if you multiply the r, g and b properties with 255 before subtracting it should be fixed.

8 Likes

Silly me. Thanks!

Just an fyi, subtracting a fixed value from a rgb will change the hue in a lot of cases.

You can multiply the color by like 0.5 to make a true safe darker version.

Or if you want to use subtraction and be accurate, use toHSV(), subtract from the V value, then plug it back into fromHSV(). Just make sure you clamp to 0

13 Likes

Awesome. Thanks!