I want to make clouds that are positioned in a region, but the Y axis keeps erroring, which says:
invalid argument #2 to 'random' (interval is empty)
The other axis works perfectly, but it’s only the Y axis that causes the error to pop up/
local randomPosition = Vector3.new(
math.random((region.Position.X - region.Size.X / 2) + cloud.Size.X / 2, (region.Position.X + region.Size.X / 2) - cloud.Size.X / 2),
math.random((region.Position.Y - region.Size.Y / 2) + cloud.Size.Y / 2, (region.Position.Y + region.Size.Y / 2) - cloud.Size.Y / 2),
math.random((region.Position.Z - region.Size.Z / 2) + cloud.Size.Z / 2, (region.Position.Z + region.Size.Z / 2) - cloud.Size.Z / 2)
)
did u try to print out the math.random statements
and your randomPosition
variable?
it could perhaps be a problem where math.random(min, max) → the min parameter could be bigger than the max parameter. eg. math.random(50, 45) hence causing it to error.
this post suggests that u could also use Random.new
instead if u still have recurring problems.
Edit:
It’s not possible to generate random numbers in Lua that are higher than the maximum value of a 32-bit integer using the math.random function (the maximum value is 2,147,483,647).
The number you have (190734863281) is higher than the maximum value.
To fix this issue, you can replace the math.random function with the Random.new function.
The Random.new constructor creates a new instance of a pseudo-random number generator that can generate random numbers within a specified range, includ…
Your right! I figured that since the regions Y axis is smaller than the clouds Y, the min and max values would be reversed.
I just removed the + cloud.Size.Y / 2
and - cloud.Size.Y / 2
part so I wouldn’t need to make the region bigger.
1 Like