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

Changing GUI Colours Randomly?

So I made a script which changes the colour scheme for two GUI's when a button is pressed. It prints the random colour numbers but does not visually change the colour. Any help?

colorgui = script.Parent.ColorChange
function colorChange()
	local MessageGui = script.Parent.MessageGui
	MessageGui.BackgroundColor3 = Color3.new(math.random(300), math.random(300), math.random(300))
	print(MessageGui.BackgroundColor3) --DEBUG
	colorgui.BackgroundColor3 = MessageGui.BackgroundColor3
end

colorgui.MouseButton1Down:connect(colorChange)

2 answers

✓ Accepted answer

Problem 1:

Color3 values only go up to 255.

Problem 2:

You need to specify two numbers when using math.random().

E.G

math.random(1,10) -- random number between 1 and 10

Problem 3:

To avoid bugs, do this when changing Color3 values:

Color3.new(number/255,number/255,number/255)

3 comments

0

Thanks! I'm not exactly great at this yet. :P

0

Actually, Color3 is only between 0 and 1, and the two arguments in math.random aren't needed. math.random(1, 10) is the same as math.random(10)

0

Really? Thanks!

Color3 takes a number between 0 and 1. If you want to use a higher number, you have to divide it by that same number to again receive a value between 0 and 1.

MessageGui.BackgroundColor3 = Color3.new(math.random(300)/300, math.random(300)/300, math.random(300)/300)

Or you can just not supply any arguments, in which case math.random will give you a number between 0 and 1;

MessageGui.BackgroundColor3 = Color3.new(math.random(), math.random(), math.random())

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