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

Help with while true loop?

Asked by 9 years ago

So I'm making a game and I want the logo's text color to change randomly every .2 seconds, so the whole thing is flashing.

Here's the script:

while true do
    local num1 = math.random(0, 255)
    local num2 = math.random(0, 255)
    local num3 = math.random(0, 255)

    script.Parent.TextColor3 = Color3.new(num1, num2, num3)
    wait(.2)
end

It's very confusing what happens. The text color changes once, and it always turns white. I'm totally confused with it, because even when I go to the properties, after it's text color has changed white, it still says that it's at the default color. So, anyway, I have absolutely no what's up. If anyone could help figure out what's wrong, it'd be appreciated.

2 answers

Log in to vote
2
Answered by
Tkdriverx 514 Moderation Voter
9 years ago

Color3.new only accepts numbers from 0 to 1. Just doing math.random() generates a random number between 0 and 1. Which is perfect for this, so we are going to use this.

Just simply do this:

while true do
    script.Parent.TextColor3 = Color3.new(math.random(), math.random(), math.random())
    wait(0.2)
end
Ad
Log in to vote
0
Answered by 9 years ago

If you'd want the GUI to flash in random colors then you could do like this:

while wait(.2) do

script.Parent.TextColor3 = Color3.new(math.random(1,255)/255,math.random(1,255)/255,math.random(1,255)/255)

end

Because when manipulating color3's you have to set the color to a number out of 255. Its kind of hard to explain. But for an example, if you'd want to set the color to (132,20,11) [That was a totally random number]

You'd have to set it too Color3 = Color3.new(132/255,20/255,11/255)

So number/255

Answer this question