I'm trying to figure out how i can make a brick transition between colors smoothly. Im trying to make it transition through all the colors of the rainbow. I mean, its a simple thing, but i cant seem to figure out how to accomplish that.
Roblox has default brick colors. You can't add more. Here's a link to all the Color Codes.
The closest you can come is by using Color3
, but even then roblox picks the closest BrickColor
to that Color3
color.
If you want to try this though, there a Color3
lerp
function. Example,
1 | local start = Color 3. new( 1 , 1 , 1 ) -- White |
2 | local End = Color 3. new( 1 , 0 , 0 ) --Red |
3 |
4 | for i = 0 , 1 , 0.03 do |
5 | wait() |
6 | local color = start:lerp(End,i) |
7 | end |
Using this method is great for GUIs, because they use the exact color3 value.
1 | -- Inside Frame |
2 | local start = Color 3. new( 1 , 1 , 1 ) -- White |
3 | local End = Color 3. new( 1 , 0 , 0 ) --Red |
4 |
5 | for i = 0 , 1 , 0.03 do |
6 | wait() |
7 | script.Parent.BackgroundColor 3 = start:lerp(End,i) |
8 | end |
For BrickColors though, it's obviously not as smooth.
1 | -- Inside Part |
2 | local start = Color 3. new( 1 , 1 , 1 ) -- White |
3 | local End = Color 3. new( 1 , 0 , 0 ) --Red |
4 |
5 | for i = 0 , 1 , 0.03 do |
6 | wait() |
7 | local color = start:lerp(End,i) |
8 | script.Parent.BrickColor = BrickColor.new(color) |
9 | end |
You could make a randomly changing color brick by doing this,
01 | -- Inside Part |
02 | local start = Color 3. new( 1 , 1 , 1 ) |
03 |
04 | while true do |
05 | start = Color 3. new( 1 , 1 , 1 ) -- Whit/LastColor |
06 | local End = Color 3. new(math.random(),math.random(),math.random()) -- Random Color |
07 | for i = 0 , 1 , 0.03 do |
08 | wait() |
09 | local color = start:lerp(End,i) |
10 | script.Parent.BrickColor = BrickColor.new(color) |
11 | end |
12 | start = End -- Resets Start variable |
13 | end |
You could maybe use Surface Guis
to make the brick transition smoother.
Good Luck!
Making a rainbow cycling brick is really easy. The easiest way is to use BrickColor
:
1 | local rainbowbrick = script.Parent |
2 |
3 | while true do |
4 | rainbowbrick.BrickColor = BrickColor.new( "the first BrickColor you want the part to change to" ) |
5 | wait( --interval between colors in seconds) |
6 | rainbowbrick.BrickColor = BrickColor.new( "the second BrickColor you want the part to change to" ) |
7 | wait( --interval between colors in seconds) |
8 | --And keep adding the BrickColor lines and waits. Make sure a wait is on the last line. |
9 | end |
The BrickColor
is the name of the color that you want to change the brick to. To get the name, hover over the color in the 'Color' dropdown in the 'Model' section in Studio.
I hope this works for you! It works in my game too. Here's an example:
01 | local rainbowbrick = script.Parent |
02 |
03 | while true do |
04 | wait( 1 ) |
05 | rainbowbrick.BrickColor = BrickColor.new( "Really red" ) |
06 | wait( 1 ) |
07 | rainbowbrick.BrickColor = BrickColor.new( "Deep orange" ) |
08 | wait( 1 ) |
09 | rainbowbrick.BrickColor = BrickColor.new( "New Yeller" ) |
10 | wait( 1 ) |
11 | rainbowbrick.BrickColor = BrickColor.new( "Forest green" ) |
12 | wait( 1 ) |
13 | rainbowbrick.BrickColor = BrickColor.new( "Cyan" ) |
14 | wait( 1 ) |
15 | rainbowbrick.BrickColor = BrickColor.new( "Magenta" ) |
16 | end |
Try this, Put it inside the part you want to 'rainbowify'
1 | part = script.Parent |
2 |
3 | while true do |
4 | wait(. 1 ) |
5 | part.BrickColor = BrickColor.Random() |
6 | end |