Get a random question

Hi, I would like to get a random question out of the table. However, I have no idea on how to do so. Can someone help? Here is my current code and it gives an error; invalid argument #2 to ‘random’ (interval is empty):

Status.Value = data[math.random(1,#data)]
local table = {put your questions here}

print(table[math.random(1, table.getn(table))

But i want to do this from a server script. So basically I want to get a random question/entry from the module script and make it a variable in this server script im requiring the module from.

What will work depends on how your question table looks. If your table is a dictionary, which means indexed with strings like this:

questions = {
"question one" = 3,
"question two" = 12

then the # operator will not give you the length, it will probably give you zero, which is consistent with your error.

1 Like

That is because your table is empty. What does it contain?

1 Like

Oops, forgot this topic existed. I fixed it! Thank you and everyones time and help!

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.