How to get the BackgroundColor3 of a Frame to print out?

I’m trying to print the BackgroundColor3 of a Frame, but it prints out in a 0-1 range instead of 0-255 like you’d expect.

My code is

print(script.Parent.BackgroundColor3)

Really short post but that’s my issue. If you know why this happens (Maybe it’s intended?) let me know. :slight_smile:

Say the decimal is .3333, multiplying that by 255 is 84.9915.
How would I round that?

round is

math.floor(x * 10^decimals  + 0.5)/10^decimals

If you wanted an integer, decimals would be 0

You can use string.format(‘%0.2f’, number) or a few other methods

you cannot multiple a color3? you need to get the r,g,b values then multiply them.

3 Likes
local color = script.Parent.BackgroundColor3
local r, g, b = color.r, color.g, color.b
-- %0.f : Round and truncate the decimal portion of each number.
local str = string.format("%0.f, %0.f, %0.f", r*255, g*255, b*255)
print(str) -- `85, 85, 85` if color was something like .3333, .3333, .3333
12 Likes

Thanks!

Why are you using %0.f over %d; is there a specific reason?

%d rounds down always. 1.9999 gets round down to 1.

2 Likes