I ask this because I want to make a championship of more painted blocks.
StevenUniverse, I will help you!!!
Ok, say you have a part (the block) in the workspace, ok?
You wanna insert a script in the part, and write this in:
1 | --First, we will set the 'block' variable |
2 | local block = script.Parent |
3 |
4 | --Ok, now, we are going to tell the script to do an action if the part is touched. |
5 | script.Parent.Touched:connect( function () |
6 | --Here inside, we would change the color. |
7 | end ) |
Now here's the problem. I don't know which color you want to put in, so I'm just going to put it color change randomly.
To make a random number, you have to use
1 | math.random( 0 , 255 ) --Inside you can put extreme values, for example math.random(1, 2), there, the value would always be between 1 and 2. I wrote 0, 255, because a color can go from 0 to 255 in each rgb value. |
So, if you want the part's color to change to a random value, the final script would be this one:
01 | --Set the 'block' variable |
02 | local block = script.Parent |
03 |
04 | --Set the activated variable, so it won't change EVERYTIME the player moves if he is touching the part |
05 | local activated = false |
06 |
07 | --Ok, now, we are going to tell the script to do an action if the part is touched. |
08 | block.Touched:connect( function () |
09 | if activated = = false then |
10 |
11 | --change the activated variable to true, so the color change won't trigger again. |
12 | activated = true |
13 | --Here inside, we would change the color to a random one: We will change the "r" to a random number, just like the "g" and "b" (rgb = red, green, blue and it's a color pattern) |
14 |
15 | block.Color = Color 3. new (math.random( 0 , 255 )/ 255 , math.random( 0 , 255 )/ 255 , math.random( 0 , 255 )/ 255 ) |