# Bad argument #2 (interval is empty) on math.random()

Hello! I’m currently attempting to create a new part, and move that part at a random position, between some extremities.

I’ve created 4 parts in a North, South, East and West formation, took the X or Z position, depending on the part, and created this code:

``````local Extremities = script.Parent.Extremities

local N = Extremities:FindFirstChild("N").Position.Z
local S = Extremities:FindFirstChild("S").Position.Z
local E = Extremities:FindFirstChild("E").Position.X
local V = Extremities:FindFirstChild("V").Position.X

while wait(math.random(2,5)) do
local Spill = Instance.new("Part")
Spill.Parent = game.Workspace
Spill.Position = Vector3.new(math.random(E,V),script.Parent.Position.Y,math.random(N,S))
end
``````

(I’ve removed what isn’t necessary, such as details about the part’s colour, size, etc.)

This is the error (Line 24 is where the command usually is put, but everything else in the script works, and it doesn’t interfere with the position values):

I’m judging it’s something wrong with the way I formulated the Vector3.new(), but I can’t seem to figure out exactly what I did wrong.

I’d love some help. Maybe something stupid I skipped over.

math.random gives that error if

1. the interval is empty
2. the order is wrong. The order should be from the smaller value to the larger one. eg: math.random(-1,1)

edit: or any format that isn’t approved

2 Likes

`math.random` don’t support float data types, convert the variables `N`, `S`, `E`, `V` to integer by rounding/flooring them.

2 Likes

Alright, but in this case, it would be simpler for me to manually add in extremities in the script, rather than do a lot of if then checks.

Is there any simpler way to organize this?

Edit: Think I got an idea.

Thanks for the info. Added it in, but the error still persists.

If you’re talking about checking which value is smaller you can do it like this:

``````local Smaller=E<=V and E or V
local Larger=E>V and E or V
``````