How would I make a random ore generation system

Hello everyone,

I’m trying to make ore generation system for my game however I unable to think of a good way.

The best I thought of is storing each possible position for the ore in a module script. But since every room can only contain certain ores you can have rare ores in the exposed cave (which isn’t supposed to happen)

What would be the best way to make it? . If you have any YouTube video or a tutorial I would be thankful.

You can take a position and put it through a noise function (math.noise(position.X / 100, position.Y / 100, position.Z / 100)) and then see if the number that the noise function gives (should be in between -0.5 and 0.5, it sort of acts like a sine wave where the peaks have random heights) is within a range of numbers that can be smaller the rarer the ore is.

I never used math.noise before. Could you demonstrate how would the script look like?

local position =
--the position of where you might want to place an ore

local range =, 0.79)
--the smaller the range the rarer the ore is
local scale = 100
--how spread out the ores are, if the scale is 1 there will be ores everywhere
--if the scale is really high and/or the range is too large ores will clump together

local value = math.noise(position.X / scale, position.Y / scale, position.Z / scale)
local placeOre = value > range.Min and value < range.Max

I suggest experimenting with the noise function as it doesnt always do what you expect

There many other resources about this that already exist:

If you don’t want rare ores to be in a certain area, then change the ore rarity for each section of your cave system.

If you don’t want rare ores to be exposed, check neighbouring positions to see if it is air.
code example for exposure checking:

local position =
--the position of a rare ore

local overlapParams =
overlapParams.FilterType = Enum.FilterType.Whitelist
overlapParams.FilterDescendantsInstances = {}
--table of instances whose descendants are the parts that make up the caves

local distance = 1
--distance of neighbouring positions

local isExposed = false

for _, direction in {Vector3.xAxis, -Vector3.xAxis, Vector3.yAxis, -Vector3.yAxis, Vector3.zAxis, -Vector3.zAxis} do
  local checkPosition = position + direction * distance

  local parts = workspace:GetPartBoundsInRadius(checkPosition, distance / 2 - 0.01, overlapParams)

  if #parts == 0 then
    isExposed = true

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.