Color3 weirdness

So my plan in this bit is for the background on the TV to flick through a set of four colours: blue, green, yellow and red.


This is done through a SurfaceGUI with a LightInfluence of 0. Note the shade of blue.
This is my script.

local red = Color3.new(255, 0, 0)
local blue = Color3.new(0, 130, 255)
local yellow = Color3.new(255, 255, 0)
local green = Color3.new(0, 255, 0)

local background = script.Parent.Frame

while true do
background.BackgroundColor3 = red
wait(1)
background.BackgroundColor3 = blue
wait(1)
background.BackgroundColor3 = green
wait(1)
background.BackgroundColor3 = yellow
wait(1)
end

On paper according to me, this looks fine. Play the script, however:

Every colour except for blue is correct, so why does the blue in the playback appear in a different shade? Just so you know, I’m relatively new to Color3.

Color3.new uses r, g, and b values from 0 to 1. You want to use Color3.fromRGB instead, which uses values from 0 to 255.

Your issue here is caused because Color3.new(0, 130, 255) is the same as Color3.fromRGB(0, 33150, 65025), but it caps out at 255 so it’s the same as Color3.fromRGB(0, 255, 255) i.e. that cyan color.

3 Likes

That probably explains the crazy values I was reading from the Properties panel. Going to try this.

Now it works. Thanks!

Here is a nice script you can use.

local colors = { --// Container of colors
[1] = Color3.fromRGB(255, 0, 0), --// Red
[2] = Color3.fromRGB(0, 0, 255), --// Blue
[3] = Color3.fromRGB(255, 255, 0), --// Yellow
[4] = Color3.fromRGB(0, 255, 0) --// Green
}
local background = script.Parent.Frame --// Your frame to change color

while true do
	for index = 1, 4 do
		wait(1) --// Time waiting
		background.BackgroundColor3 = colors[index] --// Colors to change to
	end
end