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

invalid argument #2 to 'random' (interval is empty)?

Asked by 4 years ago

Hello I'm Having A Error In My Code That I Don't Understand. I Making A Bomb Survival Admin Command And i Want it To Drop Bombs From The Sky And Spawn At A Random Position. I'm Not Sure What Can be Causing It. The Minus Symbol? The Decimals? I'm Not Sure What I Can Be Please Leave Your Suggestions down below.

local RandomZ = math.random(172,-104.6)
warn("The Z Location Of The Next Bomb is".. RandomZ)
0
if you want to spawn the bomb from the sky, make the object unanchored and set the y variable to the value you want to drop it from awesomemode14 68 — 4y

4 answers

Log in to vote
1
Answered by 4 years ago

Simple, you have to put the smaller number first.

local RandomZ = math.random(-104.6, 172)
Ad
Log in to vote
0
Answered by
hoth7 45
4 years ago
Edited 4 years ago

This may or may not work, but what I find that fixes it, is adding another .. collum after randomz, and they placing quotes with a period. Kind of like this. I fixed it. Also, you can't already set a value, it has to be empty

local RandomZ = math.random()
warn("The Z Location Of The Next Bomb is " .. RandomZ .. ".")
Log in to vote
0
Answered by
4thAxis 20
4 years ago

Your parameters are wrong, the first parameter must be the minimum and the 2nd must be a maximum. Example: math.random(10, 100)

Log in to vote
0
Answered by 4 years ago
Edited 4 years ago

When doing the marh.random(), your answers must be in order. I made this nifty function:

function order(a,b)
    if a<b  then
        return a,b
    else 
        return b,a
    end
end

math.random(order(172,-104.6))

As long as a and b are real numbers, you won't have that error.

Answer this question