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

(Easy) Cant change the backround of a gui to a random colour?

script.Parent.BackgroundColor3 = Backgroundcolor3.Random()

im new to gui's but I thought before I make the real project of the random colour I would test how to change the backround to random, However I cant figure out how.

1 comment

0

why did you put (easy) in the title this isn't a game with levels

3 answers

✓ Accepted answer

You can use math.random(MINIMUM INTEGER, MAXIMUM INTERGER) to generate a random number between those two numbers. You can also you if statements with math.random().

local rand = math.random(1, 2)

if rand == 1 then
-- Event
elseif rand == 2 then
-- Event
end

Another solution

local rand1 = math.random(1, 255)
local rand2 = math.random(1, 255)
local rand3 = math.random(1, 255)

GUI.BackgroundColor3 = Color3.fromRGB(rand1, rand2, rand3)

you can just use math.random to choose a random RGB value

local red = math.random(1, 255)
local green = math.random(1, 255)
local blue = math.random(1, 255)

script.Parent.BackgroundColor3 = Color3.fromRGB(red, green, blue)

Please accept my answer if it works!

You can use the Random Object for this

local Rand = Random.new()
script.Parent.BackgroundColor3 = Color3.new(Rand:NextInteger(0,1), Rand:NextInteger(0,1), Rand:NextInteger(0,1))

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