how do i make a rainbow part?
do i have to do like this?
1 | part.BrickColor = BrickColor.new( "Bright red" ) |
2 | part.BrickColor = BrickColor.new( "Lapis" ) |
3 | part.BrickColor = BrickColor.new( "Black" ) |
4 | part.BrickColor = BrickColor.new( "Pink" ) |
you have to make your part change its color. like with looping:
1 | while wait() do |
2 | part.BrickColor = BrickColor.new( "Bright red" ) |
3 | wait(. 5 ) |
4 | part.BrickColor = BrickColor.new( "Lapis" ) |
5 | wait(. 5 ) |
6 | part.BrickColor = BrickColor.new( "Black" ) |
7 | wait(. 5 ) |
8 | part.BrickColor = BrickColor.new( "Pink" ) end |
OR to make it more rainbow:
01 | local r = 1 |
02 | local g = 249 |
03 | local b = 100 |
04 | local rD = true |
05 | local gD = false |
06 | local bD = true |
07 | while wait() do |
08 | part.Color = Color 3. new(r, g, b) |
09 | if r > = 250 then rD = false elseif r < = 0 then rD = true end |
10 | if b > = 250 then bD = false elseif b < = 0 then bD = true end |
11 | if g > = 250 then gD = false elseif g < = 0 then gD = true end |
12 | if rD = = true then r = r + 1 else r = r - 1 end |
13 | if bD = = true then b = b + 1 else b = b - 2 end |
14 | if gD = = true then g = g + 2 else g = g - 1 end |
15 | end |
Hope i was able to help! good day!
That script will work, but the colors will change so fast that you won't have time to notice. That approach is better if you don't want the colors abruptly changing. You can use TweenService
to get a smooth effect. For the color cycle to keep repeating, use a while true do
loop
.
Examples: 1. Abruptly changes, but does the job!
01 | while true do |
02 | part.BrickColor = BrickColor.new( "Bright red" ) |
03 | wait( 1 ) |
04 | part.BrickColor = BrickColor.new( "Lapis" ) |
05 | wait( 1 ) |
06 | part.BrickColor = BrickColor.new( "Black" ) |
07 | wait( 1 ) |
08 | part.BrickColor = BrickColor.new( "Pink" ) |
09 | wait( 1 ) |
10 | end |
Wait()
were used. This uses a while wait() do
loop
, and changes over colors smoothly.01 | while wait() do |
02 | script.Parent.Color = Color 3. new( 255 / 255 , 0 / 255 , 0 / 255 ) |
03 | for i = 0 , 255 , 10 do |
04 | wait() |
05 | script.Parent.Color = Color 3. new( 255 / 255 ,i/ 255 , 0 / 255 ) |
06 | end |
07 | for i = 255 , 0 ,- 10 do |
08 | wait() |
09 | script.Parent.Color = Color 3. new(i/ 255 , 255 / 255 , 0 / 255 ) |
10 | end |
11 | for i = 0 , 255 , 10 do |
12 | wait() |
13 | script.Parent.Color = Color 3. new( 0 / 255 , 255 / 255 ,i/ 255 ) |
14 | end |
15 | for i = 255 , 0 ,- 10 do |
Hey there!
Your script probably isn't giving you any error - this is because there technically isn't any. However, the computer is processing your code really, really quickly. It is so fast, that you can't even see the colors changing. What you need to do is to add time in between each color change.
For example:
1 | part.BrickColor = BrickColor.new( "Bright red" ) |
2 | wait( 3 ) -- This would cause the script to pause for 3 seconds |
3 | part.BrickColor = BrickColor.new( "Lapis" ) |
If you want to make your script a little more complicated, you could make the colors change forever. You can simply do this within a loop. (Don't forget to add wait(#) between each change!)
1 | while true do |
2 | part.BrickColor = BrickColor.new( "Bright red" ) |
3 | wait( 3 ) -- This would cause the script to pause for 3 seconds |
4 | part.BrickColor = BrickColor.new( "Lapis" ) |
5 | wait( 3 ) -- This would cause the script to pause for 3 seconds |
6 | end |
If you have any more question, let me know and I'm happy to help! :)