local UsedPositions = {} local GCounts = { {Origin = 0} } game.Players.PlayerAdded:connect(function(plr) repeat wait() until plr.Character local char = plr.Character char.Parent = workspace.Players end) local function PositionKey(x, y, z) return x..","..y..","..z end local function GetOreFromId(id) for i,Ore in pairs(game:GetService("ReplicatedStorage").Ores:GetChildren()) do if Ore.Id.Value == id then return Ore end end end local function Gable(y) local lottery = {} for _,Ore in pairs(game:GetService("ReplicatedStorage").Ores:GetChildren()) do local MaxDepth,MinDepth = (Ore.MaxDepth.Value > 0 and Ore.MaxDepth.Value) or 9999,(Ore.MinDepth > 0 and Ore.MinDepth.Value) or 1 local Range = MaxDepth-MinDepth local MinDistiance = y - MinDepth local MaxDistance = MaxDepth - y local MaxRarity,MinRarity = Ore.MaxRarity.Value,Ore.MinRarity.Value local Change = math.ceil(((MinDistiance/Range)*MinRarity + (MaxDistance/Range)*MaxRarity)/2) if y >= MinDepth and y <= MaxDepth then for i = 1,Change do table.insert(lottery, Ore.Id.Value) end end end local Id = lottery[math.random(1,#lottery)] return GetOreFromId(Id) end local VectorMine = { Vector3.new(1,0,0), Vector3.new(-1,0,0), Vector3.new(0,1,0), Vector3.new(0,-1,0), Vector3.new(0,0,1), Vector3.new(0,0,-1), Vector3.new(0,2,0), Vector3.new(1,0,-1), Vector3.new(-1,0,1), Vector3.new(-1,0,-1), } local GenerateMine = { Vector3.new(0,0,0), Vector3.new(1,0,0), Vector3.new(0,1,0), Vector3.new(0,0,1), Vector3.new(1,1,0), Vector3.new(1,0,1), Vector3.new(0,1,1), Vector3.new(1,1,1), Vector3.new(-1,0,0), Vector3.new(0,-1,0), Vector3.new(0,0,-1), Vector3.new(-1,-1,0), Vector3.new(-1,0,-1), Vector3.new(0,-1,-1), Vector3.new(-1,-1,-1), Vector3.new(-1,1,1), Vector3.new(1,-1,1), Vector3.new(1,1,-1), Vector3.new(-1,1,-1), Vector3.new(1,-1,-1), Vector3.new(-1,-1,1), Vector3.new(-1,0,1), Vector3.new(-1,1,0), Vector3.new(1,-1,0), Vector3.new(0,-1,1), Vector3.new(1,0,-1), Vector3.new(0,0,0), } GenerateOre = function(x,y,z, Override, presetore, defaulth, XPMullti) XPMullti = XPMullti or 1 if (UsedPositions[PositionKey(x,y,z)]==true or Override == true) and y > 0 then local Noise = math.noise(x/25,y/15,z/25) local xrem = x % 25 local yrem = y % 15 local zrem = z % 25 local Constricted = xrem == 0 or yrem == 0 or zrem == 1 local CompactPose = Vector3.new(x,y,z) if y > 2 and ((Noise >- 0.525) or (Noise <= 0.525)) and not Constricted then UsedPositions[PositionKey(x,y,z)] = false if Override == "Branch" then local Origin = PositionKey(x,y,z) GCounts[Origin] = 0 coroutine.resume(coroutine.create((function() for i, vec in pairs(GenerateMine) do local Newpos = CompactPose + vec if UsedPositions[PositionKey(Newpos.x,Newpos.y,Newpos.z)] == nil then GCounts[Origin] = GCounts[Origin] +1 GenerateOre(Newpos.x,Newpos.y,Newpos.z,"Branch",Origin) end end end))) else local Origin = presetore for i, vec in pairs(VectorMine) do local Newpos = CompactPose + vec if UsedPositions[PositionKey(Newpos.x,Newpos.y,Newpos.z)] == nil then GCounts[Origin] = GCounts[Origin] +1 if GCounts[Origin] % 250 == 0 then wait() end GenerateOre(Newpos.x,Newpos.y,Newpos.z,"Branch",Origin) end end end else local Ore if y <= 1 and not defaulth then Ore = game.ReplicatedStorage.Ores.Stone:Clone() Instance.new("BoolValue",Ore).Name = "Claimed" elseif y <= 1 and defaulth then Ore = game.ReplicatedStorage.Ores.Stone:Clone() end Ore.CFrame = CFrame.new(0+x*6,5000+y*(-6),0 +z*6) UsedPositions[PositionKey(x,y,z)] = true Ore.Parent = workspace.Mine return Ore end end end local function DestroyOres(Ore) local compactepose = Vector3.new(0+Ore.Position.X/6,(Ore.Position.Y-5000)/(-6),0+Ore.Position.Z/6) UsedPositions[PositionKey(compactepose.x,compactepose.y,compactepose.z)] = false for i, vec in pairs(VectorMine) do local newpos = compactepose + vec if UsedPositions[PositionKey(newpos.x,newpos.y,newpos.z)] == nil then GenerateOre(newpos.x,newpos.y,newpos.z,false,nil,nil,nil) end end Ore:Destroy() end function game.ReplicatedStorage.MineOre.OnServerInvoke(Player,Ore) local compactepose = Vector3.new(0+Ore.Position.X/6,(Ore.Position.Y-5000)/(-6),0+Ore.Position.Z/6) DestroyOres(Ore) end for x = 1,26 do for z = 1,26 do GenerateOre(x,1,z,false,nil,true,0) end end
These are the two places I think where the error is:
local function Gable(y) local lottery = {} for _,Ore in pairs(game:GetService("ReplicatedStorage").Ores:GetChildren()) do local MaxDepth,MinDepth = (Ore.MaxDepth.Value > 0 and Ore.MaxDepth.Value) or 9999,(Ore.MinDepth > 0 and Ore.MinDepth.Value) or 1 local Range = MaxDepth-MinDepth local MinDistiance = y - MinDepth local MaxDistance = MaxDepth - y local MaxRarity,MinRarity = Ore.MaxRarity.Value,Ore.MinRarity.Value local Change = math.ceil(((MinDistiance/Range)*MinRarity + (MaxDistance/Range)*MaxRarity)/2) if y >= MinDepth and y <= MaxDepth then for i = 1,Change do table.insert(lottery, Ore.Id.Value) end end end local Id = lottery[math.random(1,#lottery)] return GetOreFromId(Id) end
or
local Ore if y <= 1 and not defaulth then Ore = game.ReplicatedStorage.Ores.Stone:Clone() Instance.new("BoolValue",Ore).Name = "Claimed" elseif y <= 1 and defaulth then Ore = game.ReplicatedStorage.Ores.Stone:Clone() end Ore.CFrame = CFrame.new(0+x*6,5000+y*(-6),0 +z*6) UsedPositions[PositionKey(x,y,z)] = true Ore.Parent = workspace.Mine return Ore end
I know its a long script but if you helped thanks!