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)
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)
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())