game.Player.PlayerAdded:connect(function(Player)
	Player.CharacterAdded:connect(function(Character)
		Character:WaitForChild("Torso")
		Character:SetTorsoCframe(Cframe.new(0,25050,0))
	end)
end)

local function GetOreFromId(Id)
	for i,Ore  in pairs(game.ReplicatedStorage.Ores:GetChildren()) do
		if Ore.Id.Value == Id then
			return Ore
		end
	end
	

local function Gamble(y)
	local Lottery = {}
	for _,Ore in pairs(game.ReplicatedStorage.Ores:GetChildren()) do
		local MaxDepth,MinDepth = (Ore.MaxDepth.Value > 0 and Ore.MaxDepth.Value) or 9999, (Ore.MinDepth.Value > 0 and Ore.MinDepth.Value) or 1
		local Range = MaxDepth - MinDepth
		local MinDistance = y - MinDepth
		local MaxDistance = MaxDepth - y
		local MaxRarity, MinRarity = Ore.MaxRarity.Value, Ore.MinRarity.Value
		local Chance = math.ceil(((MinDistance/Range) * MinRarity * (MaxDistance/Range) * MaxRarity) /2)
		for i=1,Chance do
			table.insert(Lottery,Ore.Id.Value)
		end
	end
	local Id = Lottery[math.random(1,#Lottery)]
	return GetOreFromId(Id)
end

local function GenerateOre(x,y,z)
	local Ore = Gamble(y):Clone()
	Ore.Parent = workspace.Mine
	Ore.Position = Vector3.new(0 + x*6,25000 + y*(-6) + z*6)
end

math.random(os.time())

for x=1,20 do
	for z=1,20 do
		GenerateOre(x, 1, z)
end

2 comments

0

Use the button at the top of the textbox when editing your question to put your code into a lua code block. It's really hard to read otherwise.

0

Give more description. You appear to be missing a few ends in your code.