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

my script says that my math.random rng interval is empty, why is this?

Asked by 3 years ago
while true do
luis = Instance.new("Part",workspace)
luis.Size=Vector3.new(5,1,5)
workspace.Part.Position=Vector3.new(math.random(252.5,138.5), math.random(-18.5,-18.5), math.random(-252.5,-137.5))
    workspace.Part:Destroy()    
    wait(2)
end

so when i try to run this rng for a instanced part, it gives me this in the output 16:06:44.136 - ServerScriptService.Script:4: invalid argument #2 to 'random' (interval is empty) plz help!

0
I think it could be that math.random can't give a random number between 18.5 and 18.5 bc they're the exact same number, however I could be wrong I'd say change the numbers and see if my theory is correct? adamson239 12 — 3y

1 answer

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

You're doing:

math.random(-18.5, -18.5)

Which is pretty useless. Same goes with:

math.random(252.5,138.5)

You're starting for max to min, supposed to be the other way around.

I suggest using the function:

local function random(min, max)
   return math.random() * (min - max) + min
end

instead, returns any number from min to max (usually this will not be an integer). So now you can use it like:

random(1, 5)

Also you're not supposed to Parent luis until you are done modifying its properties. (efficiency reasons) - that's why they deprecated the 2nd parameter of Instance.new.

Ad

Answer this question