How To Generate a Random Position in Region3

Hello.

As the title suggests, I need to generate random positions within a region3. Any help will be greatly appreciated.

3 Likes

You can do that by doing something like:

function RandomPositionInReg3(region3)
  local function getRandomInBounds(n)
    return math.random(-n, n)
  end

  local x = getRandomInBounds(region3.Size.X / 2)
  local y = getRandomInBounds(region3.Size.Y / 2)
  local z = getRandomInBounds(region3.Size.Z / 2)

  return region3.CFrame + Vector3.new(x,y,z)
end

*Completely untested and wrote in forum itself, there are bound to be typos

5 Likes