Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

How would i make this return a string intead of a number?

Asked by 9 years ago

I have this code and it returns a number instead of a string.

local items = {"Murderer","Sheriff","Innocent"}
local Person1 = math.random(#items)

2 answers

Log in to vote
1
Answered by 9 years ago

You forgot to index your table.

Perhaps you meant items[math.random(#items)]

Ad
Log in to vote
0
Answered by 9 years ago

math.random(#items) would return a random number between 1 and 3 as the length of the table is 3. Therefore, you would have to index the table with your random number as the index.

local items = {"Murderer","Sheriff","Innocent"}
local Person1 = items[math.random(#items)]

Answer this question