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

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

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!

1 comment

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?

1 answer

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.

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