local button=script.Parent
local frame=button.Parent
button.MouseButton1Click:connect(function()
print("clicked")
frame.BackgroundColor3=Color3.new(math.random(0, 255),math.random(0, 255),math.random(0, 255))
end)
✓ ANSWER ACCEPTED
Why does math.random give me huge number when i set its limit to 255?
2 answers
✓ Accepted answer
Color3.new() ranges from 0 to 1. You have to divide the R, G and B by 255 or use the range 0 to 1;
game.StarterGui.ScreenGui.Frame.BackgroundColor3 = Color3.new( math.random(), math.random(), math.random() )
2 comments
2
While this is correct, I'd like to just add that passing an argument to this function is redundant for this specific situation, since math.random() alone will return a number ranging from 0 to 1.
0
You are correct
The parameters to Color3.new are actually between 0 and 1, not 0 and 255 (as you might guess from the Properties tab).
As a result, you should use numbers from 0 to 1 instead of 0 to 255:
frame.BackgroundColor3 =
Color3.new(math.random(), math.random(), math.random())
This discussion is preserved as it was. New answers, comments, and votes are closed.

1 comment
When using Color3, you have to divide your number by 255. So math.random(1,255)/255. Alternatively, you could just use math.random() and it will give you random colors.