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

Question about table and picking random?

Asked by
Prioxis 673 Moderation Voter
8 years ago

So my game will have a max amount of players of 20 and I'm creating a weather system for my game involving a storm with lightning I want the lightning to pick a random out of the 20 and zap them if all other requirements are met but I want to know if I can do something like

chosen = playerlist[math.random(1,20)]

if there's not 20 keys in the table

1 answer

Log in to vote
2
Answered by 8 years ago

Pretty simple solution:

chosen = playerlist[math.random( #playerlist )]
0
ah thank you Prioxis 673 — 8y
Ad

Answer this question