Use this
1 | Codes = { "Mickey" , "Goofy" , "Pete" , "Sleeping beauty" , "Snow White" , "Donald Duck" } |
3 | Click.MouseButton 1 Click:connect( function () |
4 | Text.Text = "Getting your code, wait a second" |
6 | Text.Text = Codes [ math.random( 1 , #Codes) ] |
Explanation
Ok, so basically,
Your Goal ~ you have a series of objects/children in a table and now you want to select a random value
Normally we use math.random(indexstart, indexend) to get a random value from a given limit aka parameters, this function is pre-defined by ROBLOX and uses a certain algorithm to select randomly.
And, We know that we can access the elements of a table like this
tablename[index]
Coming to your problem,
We want to get a random number between 1(Since we start our index in tables from 1) and the number of elements present in the table (i.e the final index)
so what we can do is
1 | local tablename = { element 1 , element 2 , element 3 } |
2 | random_selection = tablename [ math.random( 1 , #tablename) ] |
Welp, Hope that helps!
Sorry if I explained something incorrectly, if so feel free to correct me!
~ Eat caiks