Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

My random color changer isn't working, why?

Asked by 6 years ago

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
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 Ziffixture 6913 — 6y
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 DeceptiveCaster 3761 — 6y
0
Wym? TypicallyPacific 61 — 6y
0
game.Players.LocalPlayer.PlayerGui.ScreenGui.TextLabel.TextColor3 DeceptiveCaster 3761 — 6y
View all comments (3 more)
0
Please have a look at my answer. Thanks tonyv537 95 — 6y
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) TheeDeathCaster 2368 — 6y
0
MCandRobloxUnited is doing it the long way around. Look at my answer. It works for me. tonyv537 95 — 6y

2 answers

Log in to vote
1
Answered by 6 years ago
Edited 6 years ago

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!

0
even worse DeceptiveCaster 3761 — 6y
0
you also forgot that the Roblox color spectrum uses numbers that are integers not decimals DeceptiveCaster 3761 — 6y
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.   tonyv537 95 — 6y
Ad
Log in to vote
0
Answered by 6 years ago

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
0
wrong. you can't change the gui that way and while wait() do is deprecated. DeceptiveCaster 3761 — 6y

Answer this question