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

How do I choose a random choice from this table?

Asked by 6 years ago
Edited 6 years ago

I'm trying to pick a random choice from this table and I keep on getting "bad argument #2 to 'random' (interval is empty)"

local animals = 
{['butterfly'] = {rotation = -40},
['mouse'] = {rotation = -80},
['sabercat'] = {rotation = -110},   
['elk'] = {rotation = -120},
['stallion'] = {rotation = -130},   
['cow'] = {rotation = -150},    
['bear'] = {rotation = -170},   
['crab'] = {rotation = 170},    
['owl'] = {rotation = 160}, 
['toad'] = {rotation = 150},    
['rat'] = {rotation = 140}, 
['wolf'] = {rotation = 130},    
['cat'] = {rotation = 120}, 
['lamb'] = {rotation = 110},
['squirrel'] = {rotation = 90}, 
['hound'] = {rotation = 70},    
['fox'] = {rotation = 50},  
['crow'] = {rotation = 40}, 
['hawk'] = {rotation = 30}, 
['spider'] = {rotation = 20},   
['snake'] = {rotation = 110}}

robloxrandom = animals[math.random(1, #animals)]
print(robloxrandom)

1 answer

Log in to vote
0
Answered by
xAtom_ik 574 Moderation Voter
6 years ago
Edited 6 years ago

Try this,

robloxrandom = animals[math.random(#animals)]

Instead of specifying a minimum, I just put in the table length and leave it at that, and that works for me.

Ad

Answer this question