The math.random function returns random numbers based on the given arguments. It can work in 3 ways:
No arguments:
One argument:
Two arguments
1 | print (math.random( 5 , 10 )) |
This algorithm can be used in a lot of useful ways, especially when creating a game based off random events. But, this function only returns a numerical value. Which means you have to base your random events off the numerical value it returns.
I'll give an example in the form of your scenario:
1 | local Maps = game:GetService( "ServerStorage" ).Maps:GetChildren() |
2 | local RandomMap = Maps [ math.random(#Maps) ] |
GetChildren() returns a table of children from the parent it's called on. You can index this table with a number. In this case, i indexed it with a random number. Giving me a random key (map).
Edit:
And yes, you can use this with various types of Colors, such as creating a random BrickColor, or creating a random Color3 color (for Guis, Effects, and anything that has a Color or Color3 property). Though these methods don't involve using the "random" function from the "math" table.
Here are some examples:
Using BrickColor.Random():
1 | local p = Instance.new( "Part" ,workspace) |
3 | local RandomBrickColor = BrickColor.Random() |
5 | p.BrickColor = RandomBrickColor |
You can also convert this random brick color to a Color3 value, so it can apply to any object that has a Color3 property:
3 | local RandomColor 3 = BrickColor.Random().Color |
5 | script.Parent.BackgroundColor 3 = RandomColor 3 |
Though, most people tend to stick to the method of calling math.random 3 times in place of the RGB values of Color3 like this:
3 | local RandomColor 3 = Color 3. new(math.random(), math.random(), math.random()) |
5 | script.Parent.BackgroundColor 3 = RandomColor 3 |
But either way works, so it all depends on what you like best. Hope this helped.