I'm trying to make it so when you join the game the textlabel will randomly change colors but when I test it, nothing happens and I get no errors. Why?
01 | local labelcolor = script.Parent.TextColor 3 |
02 |
03 | while true do |
04 | wait(. 5 ) |
05 | local r = math.random( 0 , 255 ) |
06 | local b = math.random( 0 , 255 ) |
07 | local g = math.random( 0 , 255 ) |
08 | labelcolor = Color 3. fromRGB(r,g,b) |
09 | wait(. 5 ) |
10 | end |
Hello,
This is one way you can randomly change the colour of the text button is by doing this. I will explain it in the script. I have done it with Color3, not Color3.fromRGB
FINAL SCRIPT USING Color3.new()
1 | -- Variables |
2 | local button = script.Parent |
3 |
4 | -- main bit |
5 |
6 | while true do -- this is an infinite loop |
7 | wait( 1 ) -- do this or the game will crash due to overloading |
8 | button.TextColor 3 = Color 3. new((math.random()), (math.random()),( math.random())) -- the reason that the brackets have been left blank will be explained |
9 | end |
So, leaving the brackets blank means that the values that themath.random()
function will return is a decimal between 0 and 1
I printed math.random()
and this was the output
1 | 0.54552773666264 |
2 | 0.2989054301143 |
3 | 0.084517205494783 |
4 | 0.24972764937719 |
5 | 0.90271937913953 |
6 | 0.86965136187734 |
and the values for Color3 have to be a number between 0 and 1, and math.random() will fetch you a multitude of decimals between 0 and 1.
If this helped, please accept it. Thanks!
Maybe try this in a local script and this script instead?
01 | local labelcolor = script.Parent.TextColor 3 |
02 |
03 | while wait( 1 ) do |
04 |
05 | local r = math.random( 0 , 255 ) |
06 | local b = math.random( 0 , 255 ) |
07 | local g = math.random( 0 , 255 ) |
08 | labelcolor = Color 3. fromRGB(r,g,b) |
09 |
10 | end |