Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
COMMUNITY QUESTION

My random color changer isn't working, why?

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

7 comments

0

I'd try adding a dely above the Script, sometimes the Scriot can fun faster than the assets can load, it won't tell you it's nil

0

I see what you're trying to do. if the script is local, change the text color from the player gui instead of the native gui

0

Wym?

0

game.Players.LocalPlayer.PlayerGui.ScreenGui.TextLabel.TextColor3

0

Please have a look at my answer. Thanks

0

When you do something like local Variable = ValueObj.Value, it's not defining the Value property, it's saving what the value is for the Value property; the simple solution's just to set the .Value each time you plan on doing it. (For example, TxtLbl.Color3 = Blah and no TxtLblColor3 = Blah)

0

MCandRobloxUnited is doing it the long way around. Look at my answer. It works for me.

2 answers

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 the math.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!

3 comments

0

even worse

0

you also forgot that the Roblox color spectrum uses numbers that are integers not decimals

0

And you clearly don't know that TextColor3 uses a number between 0 and 1. https://developer.roblox.com/api-reference/property/TextBox/TextColor3 . According to your logic, tell me a number between 0 and 1 that is an integer.  

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

1 comment

0

wrong. you can't change the gui that way and while wait() do is deprecated.

This discussion is preserved as it was. New answers, comments, and votes are closed.