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?
local labelcolor = script.Parent.TextColor3 while true do wait(.5) local r = math.random(0,255) local b = math.random(0,255) local g = math.random(0,255) labelcolor = Color3.fromRGB(r,g,b) wait(.5) 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()
-- Variables local button = script.Parent -- main bit while true do -- this is an infinite loop wait(1) -- do this or the game will crash due to overloading button.TextColor3 = Color3.new((math.random()), (math.random()),( math.random())) -- the reason that the brackets have been left blank will be explained 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
0.54552773666264 0.2989054301143 0.084517205494783 0.24972764937719 0.90271937913953 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?
local labelcolor = script.Parent.TextColor3 while wait(1) do local r = math.random(0,255) local b = math.random(0,255) local g = math.random(0,255) labelcolor = Color3.fromRGB(r,g,b) end