Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
✓ ANSWER ACCEPTED

I don't understand Random Math.random error (?)

Code:

local x = math.random(483.693, -478.769)
local y = 70.729
local z = math.random(-485.436,474.117)

Error:

ServerScriptService.ZombieSpawners.NoobZombieSpawner:19: bad argument #2 to 'random' (interval is empty)

I am trying to make it randomly pick a number between 483.693, -478.769 for the x coordinates and -485.436, 474.117 for the z coordinates but it comes up with the error above and I have no clue what i'm doing wrong.

How can I fix this?

Any help is much appreciated.

1 answer

✓ Accepted answer

math.random(a, b) is really only used for integers (whole numbers without decimals).

It requires that a < b. You have 483, -478, which is in the wrong order.

Instead, you can do

local x = -478.769 + math.random() * (483.693 - -478.769)

in order to get any number between -478.769 and 483.693 and not just whole numbers.

2 comments

0

nice!

0

Thanks for the help :)

This discussion is preserved as it was. New answers, comments, and votes are closed.