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:

11 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) is supposed to create the closest BrickColor Code to the value that was input.

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…

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 and further documentation 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)

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

Whereas part2's Color value shows "110, 105, 22", part1's Color value might round to
that of the Bronze BrickColor Code which has an RGB value of "126, 104, 63".

Even if both of these displayed the same BrickColor Code, they will appear
different due to having distinct RGB values for the Color property
--]]

Developer Hub Resources

BrickColor Documentation
BrickColor Codes

Color3 Documentation

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
4 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