local Folder = game.Workspace.OreList
local Folder2 = game.Workspace.Digged
local ores = {"Iron","Copper","Zinc","Lead","Aluminum","Nickel"}
local uncommonores = {"Diamond","Gold","Ruby"}
local rareores = {"Tektite","Platinum","Uranium"}
local legendaryores = {"Fire Crystal","Meridium","Glacierite","Unobtainium","Painite"}
local hellOres = {"Ignium","Hematite"}
local solids = {"Clay","Sand"}
local liquids = {"Lava"}
local CooldownTable = {}
local CooldownTime = 0.15
local MaxRange = 20
local function Coroutine(Function)
coroutine.resume(
coroutine.create(
Function
)
)
end
local function selectOre(ore, Y, NoLava)
local choice = math.random(1,1000000)/10000
print(choice)
local legendarychance = math.clamp(-Y/10000,0.0001,.5)
local rarechance = math.clamp(-Y/500,0.002,3)
if choice >80 and choice <90 and Y >-2500 then
local orechoice = ores[math.random(1,#ores)]
ore = orechoice
elseif choice >=50 and choice <=55 and Y <-1500 and Y >-2401 then
local uncommonchoice = uncommonores[math.random(1,#uncommonores)]
ore = uncommonchoice
elseif choice >=58 and choice <58.5 and Y <-5001 then
local hellChoice = hellOres[math.random(1,#hellOres)]
ore = hellChoice
elseif choice < rarechance +.1 and choice > rarechance -.1 and Y <-2000 then
local rarechoice = rareores[math.random(1,#rareores)]
ore = rarechoice
elseif choice < legendarychance +.001 and choice > legendarychance -.001 and Y <-4000 then
local legendarychoice = legendaryores[math.random(1,#legendaryores)]
ore = legendarychoice
elseif choice >40 and choice <=100 and Y >-500 then
local solidorechoice = solids[math.random(1,#solids)]
ore = solidorechoice
elseif Y >-250 then
ore = game.ReplicatedStorage.Ores.Dirt
elseif Y <-250 and Y >-500 then
ore = game.ReplicatedStorage.Ores.Clay
elseif Y <-500 and Y >-2000 then
ore = game.ReplicatedStorage.Ores.Stone
elseif Y <-2000 and Y >-3601 then
ore = game.ReplicatedStorage.Ores.Granite
elseif Y <-3601 and Y >-4989 then
ore = game.ReplicatedStorage.Ores.Basalt
elseif Y <-4989 then
ore = game.ReplicatedStorage.Ores.Hellstone
end
return ore
end
local ids = {
138451448, --[[ Dirt Dig ]]
138451201, --[[ Stone Dig ]]
142431247, --[[ Water Splash ]]
131323304, --[[ Gem Jingle ]]
228202017, --[[ Pop Sound ]]
156444949, --[[ Glass Break ]]
168555262, --[[ Buzzing ]]
225824796, --[[ YAY! (Grunt B-day party) ]]
178292943, --[[ Victory Sound ]]
260435164, --[[ Fire Effect ]]
282061033 --[[ Magic Fire ]]
}
local function Cover(Lava)
local Ray1 = Ray.new(Lava.Position, Lava.CFrame.LookVector * 6)
local Ray2 = Ray.new(Lava.Position, Lava.CFrame.UpVector * 6)
local Ray3 = Ray.new(Lava.Position, Lava.CFrame.RightVector * 6)
local Ray4 = Ray.new(Lava.Position, Lava.CFrame.LookVector * -6)
local Ray5 = Ray.new(Lava.Position, Lava.CFrame.UpVector * -6)
local Ray6 = Ray.new(Lava.Position, Lava.CFrame.RightVector * -6)
local Part1, Position1 = game.Workspace:FindPartOnRayWithWhitelist(Ray1, {Folder, Folder2}, false, false)
local Part2, Position2 = game.Workspace:FindPartOnRayWithWhitelist(Ray2, {Folder, Folder2}, false, false)
local Part3, Position3 = game.Workspace:FindPartOnRayWithWhitelist(Ray3, {Folder, Folder2}, false, false)
local Part4, Position4 = game.Workspace:FindPartOnRayWithWhitelist(Ray4, {Folder, Folder2}, false, false)
local Part5, Position5 = game.Workspace:FindPartOnRayWithWhitelist(Ray5, {Folder, Folder2}, false, false)
local Part6, Position6 = game.Workspace:FindPartOnRayWithWhitelist(Ray6, {Folder, Folder2}, false, false)
if Part1 == nil and Position1.Y <=-1 then
local ore = nil
local Clone = selectOre(ore,Position1.Y)
local ClonedBlock = game.ReplicatedStorage.Ores[tostring(Clone)]:Clone()
ore = nil
ClonedBlock.Parent = Folder
ClonedBlock.CFrame = CFrame.new(Position1)
end
if Part2 == nil and Position2.Y <=-1 then
local ore = nil
local Clone = selectOre(ore,Position2.Y)
local ClonedBlock = game.ReplicatedStorage.Ores[tostring(Clone)]:Clone()
ore = nil
ClonedBlock.Parent = Folder
ClonedBlock.CFrame = CFrame.new(Position2)
else
Part2:Destroy()
end
if Part3 == nil and Position3.Y <=-1 then
local ore = nil
local Clone = selectOre(ore,Position3.Y)
local ClonedBlock = game.ReplicatedStorage.Ores[tostring(Clone)]:Clone()
ore = nil
ClonedBlock.Parent = Folder
ClonedBlock.CFrame = CFrame.new(Position3)
end
if Part4 == nil and Position4.Y <=-1 then
local ore = nil
local Clone = selectOre(ore,Position4.Y)
local ClonedBlock = game.ReplicatedStorage.Ores[tostring(Clone)]:Clone()
ore = nil
ClonedBlock.Parent = Folder
ClonedBlock.CFrame = CFrame.new(Position4)
end
if Part5 == nil and Position5.Y <=-1 then
local ore = nil
local Clone = selectOre(ore,Position5.Y)
local ClonedBlock = game.ReplicatedStorage.Ores[tostring(Clone)]:Clone()
ore = nil
ClonedBlock.Parent = Folder
ClonedBlock.CFrame = CFrame.new(Position5)
end
if Part6 == nil and Position6.Y <=-1 then
local ore = nil
local Clone = selectOre(ore,Position6.Y)
local ClonedBlock = game.ReplicatedStorage.Ores[tostring(Clone)]:Clone()
ore = nil
ClonedBlock.Parent = Folder
ClonedBlock.CFrame = CFrame.new(Position6)
end
end
game.ReplicatedStorage.Dig.OnServerEvent:Connect(function(Player, ToDig, Tool)
local PlayerFind = table.find(CooldownTable, Player)
if PlayerFind == nil then
if ToDig ~= nil and ToDig:IsDescendantOf(Folder) then
local Character = Player.Character
if Character ~= nil then
local RootPart = Character:WaitForChild("HumanoidRootPart")
if RootPart ~= nil then
local Distance = (RootPart.Position - ToDig.Position).Magnitude
if Distance <= MaxRange then
table.insert(CooldownTable, #CooldownTable + 1, Player)
local Ray1 = Ray.new(ToDig.Position, ToDig.CFrame.LookVector * 6)
local Ray2 = Ray.new(ToDig.Position, ToDig.CFrame.UpVector * 6)
local Ray3 = Ray.new(ToDig.Position, ToDig.CFrame.RightVector * 6)
local Ray4 = Ray.new(ToDig.Position, ToDig.CFrame.LookVector * -6)
local Ray5 = Ray.new(ToDig.Position, ToDig.CFrame.UpVector * -6)
local Ray6 = Ray.new(ToDig.Position, ToDig.CFrame.RightVector * -6)
local Part1, Position1 = game.Workspace:FindPartOnRayWithWhitelist(Ray1, {Folder, Folder2}, false, false)
local Part2, Position2 = game.Workspace:FindPartOnRayWithWhitelist(Ray2, {Folder, Folder2}, false, false)
local Part3, Position3 = game.Workspace:FindPartOnRayWithWhitelist(Ray3, {Folder, Folder2}, false, false)
local Part4, Position4 = game.Workspace:FindPartOnRayWithWhitelist(Ray4, {Folder, Folder2}, false, false)
local Part5, Position5 = game.Workspace:FindPartOnRayWithWhitelist(Ray5, {Folder, Folder2}, false, false)
local Part6, Position6 = game.Workspace:FindPartOnRayWithWhitelist(Ray6, {Folder, Folder2}, false, false)
local FoundLava = nil
if Part1 == nil and Position1.Y <=-1 then
local ore = nil
local Clone = selectOre(ore, Position1.Y, FoundLava)
local ClonedBlock = game.ReplicatedStorage.Ores[tostring(Clone)]:Clone()
ore = nil
ClonedBlock.Parent = Folder
ClonedBlock.CFrame = CFrame.new(Position1)
if Clone.Name == "Lava" then
FoundLava = true
Cover(ClonedBlock)
end
end
if Part2 == nil and Position2.Y <=-1 then
local ore = nil
local Clone = selectOre(ore, Position2.Y, FoundLava)
local ClonedBlock = game.ReplicatedStorage.Ores[tostring(Clone)]:Clone()
ore = nil
ClonedBlock.Parent = Folder
ClonedBlock.CFrame = CFrame.new(Position2)
if Clone.Name == "Lava" then
FoundLava = true
Cover(ClonedBlock)
end
end
if Part3 == nil and Position3.Y <=-1 then
local ore = nil
local Clone = selectOre(ore, Position3.Y, FoundLava)
local ClonedBlock = game.ReplicatedStorage.Ores[tostring(Clone)]:Clone()
ore = nil
ClonedBlock.Parent = Folder
ClonedBlock.CFrame = CFrame.new(Position3)
if Clone.Name == "Lava" then
FoundLava = true
Cover(ClonedBlock)
end
end
if Part4 == nil and Position4.Y <=-1 then
local ore = nil
local Clone = selectOre(ore, Position4.Y, FoundLava)
local ClonedBlock = game.ReplicatedStorage.Ores[tostring(Clone)]:Clone()
ore = nil
ClonedBlock.Parent = Folder
ClonedBlock.CFrame = CFrame.new(Position4)
if Clone.Name == "Lava" then
FoundLava = true
Cover(ClonedBlock)
end
end
if Part5 == nil and Position5.Y <=-1 then
local ore = nil
local Clone = selectOre(ore, Position5.Y, FoundLava)
local ClonedBlock = game.ReplicatedStorage.Ores[tostring(Clone)]:Clone()
ore = nil
ClonedBlock.Parent = Folder
ClonedBlock.CFrame = CFrame.new(Position5)
if Clone.Name == "Lava" then
FoundLava = true
Cover(ClonedBlock)
end
end
if Part6 == nil and Position6.Y <=-1 then
local ore = nil
local Clone = selectOre(ore, Position6.Y, FoundLava)
local ClonedBlock = game.ReplicatedStorage.Ores[tostring(Clone)]:Clone()
ore = nil
ClonedBlock.Parent = Folder
ClonedBlock.CFrame = CFrame.new(Position6)
if Clone.Name == "Lava" then
FoundLava = true
Cover(ClonedBlock)
end
end
ToDig.Parent = Folder2
ToDig.CanCollide = false
ToDig.Transparency = 1
for Time, Thing in pairs(ToDig:GetDescendants()) do
if Thing:IsA("BasePart") then
Thing.CanCollide = false
Thing.Transparency = 1
end
end
game.Players[tostring(Player)].Inventory[ToDig.Name].Value = game.Players[tostring(Player)].Inventory[ToDig.Name].Value +1
wait(CooldownTime)
table.remove(CooldownTable, table.find(CooldownTable, Player))
end
end
end
end
end
end)
read the error at output, trust me it’s gonna give you brain damage
At some point you are not getting a correct string. Since you can see that it outputs ‘nil’ 5x first and then it gives you an error that no any objects is parent with a name as ‘nil’.
Can you show us the relevant areas of the code (around line 169)
that’s the ore im trying to print.
game.ReplicatedStorage.Dig.OnServerEvent:Connect(function(Player, ToDig, Tool)
local PlayerFind = table.find(CooldownTable, Player)
if PlayerFind == nil then
if ToDig ~= nil and ToDig:IsDescendantOf(Folder) then
local Character = Player.Character
if Character ~= nil then
local RootPart = Character:WaitForChild("HumanoidRootPart")
if RootPart ~= nil then
local Distance = (RootPart.Position - ToDig.Position).Magnitude
if Distance <= MaxRange then
table.insert(CooldownTable, #CooldownTable + 1, Player)
local Ray1 = Ray.new(ToDig.Position, ToDig.CFrame.LookVector * 6)
local Ray2 = Ray.new(ToDig.Position, ToDig.CFrame.UpVector * 6)
local Ray3 = Ray.new(ToDig.Position, ToDig.CFrame.RightVector * 6)
local Ray4 = Ray.new(ToDig.Position, ToDig.CFrame.LookVector * -6)
local Ray5 = Ray.new(ToDig.Position, ToDig.CFrame.UpVector * -6)
local Ray6 = Ray.new(ToDig.Position, ToDig.CFrame.RightVector * -6)
local Part1, Position1 = game.Workspace:FindPartOnRayWithWhitelist(Ray1, {Folder, Folder2}, false, false)
local Part2, Position2 = game.Workspace:FindPartOnRayWithWhitelist(Ray2, {Folder, Folder2}, false, false)
local Part3, Position3 = game.Workspace:FindPartOnRayWithWhitelist(Ray3, {Folder, Folder2}, false, false)
local Part4, Position4 = game.Workspace:FindPartOnRayWithWhitelist(Ray4, {Folder, Folder2}, false, false)
local Part5, Position5 = game.Workspace:FindPartOnRayWithWhitelist(Ray5, {Folder, Folder2}, false, false)
local Part6, Position6 = game.Workspace:FindPartOnRayWithWhitelist(Ray6, {Folder, Folder2}, false, false)
local FoundLava = nil
if Part1 == nil and Position1.Y <=-1 then
local ore = nil
local Clone = selectOre(ore, Position1.Y, FoundLava)
local ClonedBlock = game.ReplicatedStorage.Ores[tostring(Clone)]:Clone()
ore = nil
ClonedBlock.Parent = Folder
ClonedBlock.CFrame = CFrame.new(Position1)
if Clone.Name == "Lava" then
FoundLava = true
Cover(ClonedBlock)
end
end
if Part2 == nil and Position2.Y <=-1 then
local ore = nil
local Clone = selectOre(ore, Position2.Y, FoundLava)
local ClonedBlock = game.ReplicatedStorage.Ores[tostring(Clone)]:Clone()
ore = nil
ClonedBlock.Parent = Folder
ClonedBlock.CFrame = CFrame.new(Position2)
if Clone.Name == "Lava" then
FoundLava = true
Cover(ClonedBlock)
end
end
if Part3 == nil and Position3.Y <=-1 then
local ore = nil
local Clone = selectOre(ore, Position3.Y, FoundLava)
local ClonedBlock = game.ReplicatedStorage.Ores[tostring(Clone)]:Clone()
ore = nil
ClonedBlock.Parent = Folder
ClonedBlock.CFrame = CFrame.new(Position3)
if Clone.Name == "Lava" then
FoundLava = true
Cover(ClonedBlock)
end
end
if Part4 == nil and Position4.Y <=-1 then
local ore = nil
local Clone = selectOre(ore, Position4.Y, FoundLava)
local ClonedBlock = game.ReplicatedStorage.Ores[tostring(Clone)]:Clone()
ore = nil
ClonedBlock.Parent = Folder
ClonedBlock.CFrame = CFrame.new(Position4)
if Clone.Name == "Lava" then
FoundLava = true
Cover(ClonedBlock)
end
end
if Part5 == nil and Position5.Y <=-1 then
local ore = nil
local Clone = selectOre(ore, Position5.Y, FoundLava)
local ClonedBlock = game.ReplicatedStorage.Ores[tostring(Clone)]:Clone()
ore = nil
ClonedBlock.Parent = Folder
ClonedBlock.CFrame = CFrame.new(Position5)
if Clone.Name == "Lava" then
FoundLava = true
Cover(ClonedBlock)
end
end
if Part6 == nil and Position6.Y <=-1 then
local ore = nil
local Clone = selectOre(ore, Position6.Y, FoundLava)
local ClonedBlock = game.ReplicatedStorage.Ores[tostring(Clone)]:Clone()
ore = nil
ClonedBlock.Parent = Folder
ClonedBlock.CFrame = CFrame.new(Position6)
if Clone.Name == "Lava" then
FoundLava = true
Cover(ClonedBlock)
end
end
ToDig.Parent = Folder2
ToDig.CanCollide = false
ToDig.Transparency = 1
for Time, Thing in pairs(ToDig:GetDescendants()) do
if Thing:IsA("BasePart") then
Thing.CanCollide = false
Thing.Transparency = 1
end
end
game.Players[tostring(Player)].Inventory[ToDig.Name].Value = game.Players[tostring(Player)].Inventory[ToDig.Name].Value +1
wait(CooldownTime)
table.remove(CooldownTable, table.find(CooldownTable, Player))
end
end
end
end
end
end)