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

Random Rgb color doesn't change ?

Asked by 6 years ago

Hi i tried to make a "rgb" generator

local R = math.random(0,255)
local G = math.random(0,255)
local B = math.random(0,255)

while wait(0.5) do
    print(R,G,B)
end

It works fine but it doesn't generate randomly.

Output :

138 147 6
ContentProvider:PreloadAsync() failed for rbxassetid://99666917
138 147 6 (6x)

I always get the same result but if i stop and i play again it change

(Hope you understand and sorry for my english)

1 answer

Log in to vote
0
Answered by 6 years ago

You’re only generating the random numbers once, that’s why.

Put the values in the loop so it will randomly generate the numbers constantly. You don’t even need to set up variables for it actually.

Here’s how I would do it :

while wait(.5) do
    print(math.random(255), math.random(255), math.random(255))
end

but if you want the variables, here’s how you would put it :

while wait(.5) do
    local R = math.random(0, 255)
    local G = math.random(0, 255)
    local B = math.random(0, 255)
    print(R, G, B)
end

Hope this helped!

0
Thanks ! xJathur95x 129 — 6y
Ad

Answer this question