Strange Color3.new() Behavior

Hello, I am trying to make a script that when you click a button it will change the button’s color.

I am not a noob and I know how to do this but for some odd reason when my code runs

Code:

local bool = script.Parent.BoolValue

script.Parent.MouseButton1Click:Connect(function()
	if bool.Value == false then
		script.Parent.BackgroundColor3 = Color3.new(255, 78, 8)
		bool.Value = true
	else
		script.Parent.BackgroundColor3 = Color3.new(255, 160, 7)
		bool.Value = false
	end
end)

And I’m sure that this would normally work, but instead, the background color goes to the color3 values of 65025, 40800, 1785!!!

HOIW

I honestly don’t know how this is possible, if you could help me out that’d be great, Thanks!

Check the developer page for it, color3.new takes arguments from 0 to 1.
Use Color3.fromRGB.

2 Likes

You have to use Color3.fromRGB instead of Color3.new

aw damn so close to being first LOL

1 Like

Color3.new() can be either RGB or HSV and i think its a bug. I dont recommend using Color3.new() because they take the same argument and confuses script what to use

1 Like

@ikanbuntal12 and @55167233gf

It’s not actually a bug, they are just using Color3 incorrectly.

3 Likes

You need to

Color3.new(255/255, 160/255, 7/255)

Basically divide each RGB value by 255

Or you can

Color3.fromRGB(255, 160, 7)
6 Likes

Color3.new() takes same argument as Colo3.FromRGB and Color3.FromHSV,and as i said it causes a confuses in the script

1 Like

Color3.new() parameters range from values inbetween 0-1. There are multiple ways to fix this, to convert it into RGB format you could divide each of the values by 255 such as the following:

script.Parent.BackgroundColor3 = Color3.new(255/255, 78/255, 8/255)

Alternatively, you can use Color3.fromRGB to work directly with RGB values.

script.Parent.BackgroundColor3 = Color3.fromRGB(255, 78, 8)

You can find the Color3 Developer API here for more information:
https://developer.roblox.com/en-us/api-reference/datatype/Color3

Edit: Sorry for some duplicate information, I was gathering resources in the time span while other responses were made. I’ve also corrected an error in the line of code.

2 Likes

But that’s not Color3.new. That’s Color3.fromRGB and Color3.fromHSV. Just because they all use three numbers is no reason to avoid them. It’s a good reason to learn to read documentation though.

1 Like

Use Color3.fromRGB() instead. Color3.new uses values from 0-1, fromRGB uses values from 0-255 which is probably what you want

1 Like

What you’re saying is not exactly true. Color3.new() and Color3.fromHSV are expecting numbers in the range of [0,1] and Color3.fromRGB expects a range of [0,255].

By this I believe you meant Color3 and not Color3.new(). Color3 by default expects you to use value ranges of [0,1] but Color3.fromRGB() is added to do the math that will convert the [0,255] color range to fit into a [0,1] range. The whole API reference on Color3 is linked below.

Color3 API Reference

Color3 is a data type that describes a color using R, G and B components, which are on the range [0, 1].

1 Like