Hi. So I’m trying to pick one string from this table (provided below), but every time i try, instead of printing the value, it prints nil.
Any help is appreciated!!
my code:
local partymodes = {
"speed",
"item drop",
"jump boost",
"darkness",
"item drop",
"coins",
"fatigue",
"super fatigue"
}
local value = math.random(1,#partymodes) -- Get random number with 1 to length of table.
local mode = table[value] -- Pick value from table
print(mode)
The issue specifically is you’re indexing the wrong table. You have a table defined as partymodes but are indexing the table “class”.
What you need to do is this:
local partymodes = {
"speed",
"item drop",
"jump boost",
"darkness",
"item drop",
"coins",
"fatigue",
"super fatigue"
}
local value = math.random(1,#partymodes) -- Get random number with 1 to length of table.
local mode = partymodes[value] -- Pick value from table
print(mode)