Change a parts color

Hello… So I encountered something really weird that always worked for me until now:/
I inserted a script into a part in the workspace.
In the script I wrote;

while true do

script.Parent.Color = Color3.new(255,0,0)

wait(1)

script.Parent.Color = Color3.new(0,255,0)

wait(1)

end

IT DID NOT WORK?!?!?! Someone explain.
Thank you :smile_cat:

13 Likes

Color3 values operate on a 0-1 scale. The 0-255 scale is for RGB (Red/Green/Blue) values.

If you want to use the RGB scale to create a Color3 value, use the Color3.fromRGB() constructor (I forgot about this at the time of making my post, thank you @colbert2677 for reminding me).


Additionally, keep in mind that BrickColor.new(R, G, B) will create the closest BrickColor Code to the value that was input (although this will be on a 0-1 scale rather than the 0-255 scale). The RGB values for each existing BrickColor Code can be found on this Roblox Creator Documentation page.

Note

(At the time of editing this comment on January 26th, 2022, to add Example #2, this behavior doesn’t appear to be working properly. Most RGB values that I’ve input to the BrickColor.new() constructor results in “Institutional White” with an RGB value of “248, 248, 248”, even if one of the values is 1 off from a completely different BrickColor Code).

After coming back to this comment on February 9th, 2023, I’m still observing the same behavior…

(Update on April 1st 2024)
I decided to revisit this, and it turns out that the behavior of using BrickColor.new() with 3 sets of numbers (rather than a specific BrickColor code) is actually meant to be based on a 0-1 scale rather than 0-255. That’s why when I input anything above 1 for each of the values, it immediately turned into “Institutional White”, which has the values of [0.973, 0.973, 0.973]. It feels unintuitive, though, because that format resembles Color3 more than BrickColor.


If you are looking to update the part’s Color to the exact RGB values on the 0-255 scale, it’s recommended to utilize Color3.fromRGB(), instead. Examples can be found below:

Example 1

local part1 = workspace.Part1
local part2 = workspace.Part2

part1.BrickColor = BrickColor.new(255, 0, 0)
part2.Color = Color3.fromRGB(255, 0, 0)

--[[
These two lines of code will result in the same color because a BrickColor code
with (255, 0, 0) as its RGB components exist (the color is called "Really Red")
--]]

Example 2

local part1 = workspace.Part1
local part2 = workspace.Part2

part1.BrickColor = BrickColor.new(110, 105, 22)
part2.Color = Color3.fromRGB(110, 105, 22)

--[[
This will result in different colors because a BrickColor Code
with (110, 105, 22) as its RGB components does not exist.

While part2 would have the exact RGB components of (110, 105, 22),
part1's Color value would round to that of the "Institutional White"
BrickColor Code. This is because using BrickColor.new(R, G, B) to create
a color that isn't defined as an existing BrickColor Code will
automatically round to the nearest BrickColor Code based on a 0-1 scale
rather than 0-255, for some reason.

"Institutional White" is said to have an RGB Value of [0.973, 0.973, 0.973],
so if you try to use BrickColor.new(R, G, B) with all 3 values greater than 1,
it'll probably select that color every time. It feels a bit unintuitive that it
doesn't use the 0-255 scale in that case, so I would recommend using
Color3.fromRGB(R, G, B) to get the specific RGB values you're looking for.
--]]
21 Likes

You can still use the Color property and the RGB scale if you use the fromRGB constructor of Color3. Would recommend this over that weird BrickColor constructor override.

part.Color = Color3.fromRGB(255, 0, 0)
4 Likes

Try this:

while true do

script.Parent.Color = Color3.fromRGB(255,0,0)

wait(1)

script.Parent.Color = Color3.fromRGB(0,255,0)

end

This is because the Color3 statement is for RGB.

1 Like

I’ve found a fully working method if you want to try this:

local part = game.Workspace.(Part Name)
part.BrickColor = BrickColor.new(“Really red”)
wait(1)

while wait() do

wait(0.1)
if part.BrickColor == BrickColor.new("Really red") then
	wait(1)
	part.BrickColor = BrickColor.new("Lime green")
	wait(1)
end

if part.BrickColor == BrickColor.new("Lime green") then
	wait(1)
	part.BrickColor = BrickColor.new("Really red")
	wait(1)
end

end

If this worked for you please tell me. :smiley:

8 Likes

Hmm, what about try

part.Color = Color.new(255,0,0)
-- Or Try:
part.BrickColor = BrickColor.new("Really Red")
4 Likes

Its a part so you would want to use brick color

while true do

script.Parent.BrickColor = BrickColor.new(pick color)

wait(1)

script.Parent.BrickColor = BrickColor.new(pick color)

wait(1)

end
5 Likes

Color3 in parts operates the RGB way.

@StrongBigeMan9 already explained RGB here, I suggest reading their post if you want an explanation of how RGB works, they explained it way better than I can.

Basically, if you want to change the color3 of a part, do this:

script.Parent.Color = Color3.fromRGB(0, 255, 0)

So your script should look like this:

while true do

script.Parent.Color = Color3.new(255,0,0)

wait(1)

script.Parent.Color = Color3.new(0,255,0)

wait(1)

end