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

Math.random error (interval is empty)?

Asked by 6 years ago

Error: 'Bad argument#2 to 'math.random' (interval is empty)

1local murderers = math.random(2, #game.Players:GetPlayers())

The script doesn't work. The error is above

1 answer

Log in to vote
0
Answered by
Rare_tendo 3000 Moderation Voter Community Moderator
6 years ago

bad argument #2 to 'math.random' (interval is empty): This error occurs when the first argument, or the first number inputted, is more than the 2nd argument.

The first argument of math.random will be the minimum number, while the second argument of math.random will be the maximum number.

1local list = game.Players:GetPlayers()
2local rand1 = math.random(1, #list)
3local murderer1 = list[rand1]
4table.remove(list, rand1)
5 
6local rand2 = math.random(1, #list)
7local murderer2 = list[rand2]
0
Thank you! Gomlsauresrex -12 — 6y
Ad

Answer this question