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

now why can't I do this? "bad argument #2 (interval is empty)"

Asked by
Vlym 19
4 years ago
local velocityPlatform = game.Workspace.VelocityPlatform

function vel(z)
    velocityPlatform.Velocity = Vector3.new(0,0,z)
    wait(2)
end

while true do
    vel(math.random(-5,-200))
end

2 answers

Log in to vote
-1
Answered by 4 years ago

math.random() expects integers to be given in ascending order, so the smaller integer must come before the larger one. In your case this doesn’t happen (-5 > -200), hence the error is seen. The interval b-a for math.random(a, b) can’t be negative. Just rearrange the numbers:


local velocityPlatform = game.Workspace.VelocityPlatform function vel(z) velocityPlatform.Velocity = Vector3.new(0,0,z) wait(2) end while true do vel(math.random(-200, -5)) -- You could also do vel(-math.random(5, 200)) end
Ad
Log in to vote
0
Answered by
iuclds 720 Moderation Voter
4 years ago
Edited 4 years ago
local velocityPlatform = game.Workspace.VelocityPlatform

function vel(z)
    velocityPlatform.Velocity = Vector3.new(0,0,z)
    wait(2)
end

while true do
    vel(math.random(-200,-5))
end

You have to put the smaller number then the bigger number. It's a simple change, but can be unnoticeable. I'd prefer this instead :

-math.random(5,200)

Answer this question