Note, this isn’t my code. I’ve just found it from the toolbox and made a few edits to clean it up.
local function RandomChance(number)
if type(number) == 'number' and number < 100 then
if math.random(number, 1000) < 500 then
if math.random(number, 100) == math.random(number, 100) then
return true
else
return false
end
else
if math.random(1, 1337) == 777 then
return true
else
return false
end
end
else
return false
end
end
local function GetBlock(position)
local Add = math.random(1, 10)
local NonLayerChance = 100
if Add and position then
if position > LayerLimits.Dirt then
NonLayerChance = 90
Add = tonumber(math.abs(math.floor((position - LayerLimits.Surface) / 100)) + math.random(1, 10)) or 1
elseif position > LayerLimits.Stone then
NonLayerChance = 80
Add = tonumber(math.abs(math.floor((position-LayerLimits.Surface) / 100)) + math.random(15, 30)) or 1
elseif position > LayerLimits.Marble then
NonLayerChance = 70
Add = tonumber(math.abs(math.floor((position-LayerLimits.Surface) / 100)) + math.random(25, 50)) or 1
elseif position > LayerLimits.Granite then
NonLayerChance = 60
Add = tonumber(math.abs(math.floor((position-LayerLimits.Surface) / 100)) + math.random(35, 70)) or 1
elseif position > LayerLimits.Obsidian then
NonLayerChance = 50
Add = tonumber(math.abs(math.floor((position-LayerLimits.Surface) / 100)) + math.random(60, 120)) or 1
else
NonLayerChance = 40
Add = tonumber(math.abs(math.floor((position-LayerLimits.Surface) / 100)) + math.random(75, 150)) or 1
end
else
NonLayerChance = 100
Add = 1
end
if math.random(1, GetChance(11, (23 - Add))) == 1 and (position > LayerLimits.Granite) then
return Blocks['Copper']
elseif math.random(1, GetChance(11, 27 - Add)) == 1 and (position > LayerLimits.Obsidian) then
return Blocks['Silver']
elseif math.random(1, GetChance(11, 32 - Add)) == 1 and (position < LayerLimits.Dirt) then
if RandomChance(7) then
return Blocks['Amethyst']
else
return Blocks['Gold']
end
elseif math.random(1, GetChance(18, 35 - Add)) == 1 and (position < LayerLimits.Stone) then
if RandomChance(8) then
return Blocks['Amethyst']
else
return Blocks['Ruby']
end
elseif math.random(1, GetChance(14, 32 - Add)) == 1 and (position < LayerLimits.Stone) then
if RandomChance(9) then
return Blocks['Amethyst']
else
return Blocks['Sapphire']
end
end
end
Looking at these lines
if math.random(1, GetChance(11, (23 - Add))) == 1 and (position > LayerLimits.Granite) then
return Blocks['Copper']
elseif math.random(1, GetChance(11, 27 - Add)) == 1 and (position > LayerLimits.Obsidian) then
return Blocks['Silver']
elseif math.random(1, GetChance(11, 32 - Add)) == 1 and (position < LayerLimits.Dirt) then
if RandomChance(7) then
return Blocks['Amethyst']
else
return Blocks['Gold']
end
elseif math.random(1, GetChance(18, 35 - Add)) == 1 and (position < LayerLimits.Stone) then
if RandomChance(8) then
return Blocks['Amethyst']
else
return Blocks['Ruby']
end
end
As every ore I find is either Copper, Silver, or Ruby. So I’m guessing the math.random isn’t that random, as it’s never getting furhter into the script to give off other ores. Is there a better to do this? I feel it’s too clunk but I don’t know how to successfully have it be random, but still increase odds of finding rare ores the further down a player is