Math.random prints number not table text

Hello,

I’m trying to print a random role from the table. Instead of printing the text such as “killer” or “spy” it prints the number of the location in the table. How do I fix this?

Thanks, Skylexion

You are asking it to print a number between 1 and the length of the table. What I think you want is
print(Table[math.random(#table0])

Adding on to the above post, I’ll attempt to give an explanation:

print(math.random(#Table))

This will just print a random position from how much things there are in the table (1, 4, 9, 3, etc)

To fix this, you should first get the Table[] then set your math.random function that way so that it’s looking for a value

  • Index is the Ordered Number

  • Value is the actual Name you’re trying to obtain

Fixed:

print(Table[math.random(1, #Table)]
1 Like