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

What does this mean?

Asked by 9 years ago

Please make your question title relevant to your question content. It should be a one-sentence summary in question form.

It comes out in my output:

bad argument #2 to 'random' (interval is empty)

2 answers

Log in to vote
-1
Answered by 9 years ago

It means that you made an error in argument 2(the second number)

Ad
Log in to vote
0
Answered by
BlueTaslem 18071 Moderation Voter Administrator Community Moderator Super Administrator
9 years ago

Breaking down the error:

  • bad argument #2: The second value you gave to a function was "bad" (didn't make sense)
  • to 'random': The function that was given a bad value was math.random
  • (interval is empty): This is a hint explaining why the value was bad.

The 2-parameter use of math.random is math.random(low, high).

If high is less than low, then the interval [low, high] (in math notation) is empty -- there is no number at least low and less than high.


A frequent cause of this error is code that looks like this:

list = {}

print( math.random(1, #list) )

This is a problem, since #list is 0 and 0 is less than 1.

Usually, it's not so obvious -- more likely, you're using :GetPlayers() or :GetChildren() when there are none.

Answer this question