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)

local 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.

local list = game.Players:GetPlayers()
local rand1 = math.random(1, #list)
local murderer1 = list[rand1]
table.remove(list, rand1)

local rand2 = math.random(1, #list)
local murderer2 = list[rand2]
0
Thank you! Gomlsauresrex -12 — 6y
Ad

Answer this question