I’m making a voxel based mining game, everything’s working fine and smoothly except for one issue that I’ve come across recently
I tried adding abilities to the pickaxes in which would mine more blocks, this works fine until the mine resets, there’s functionality to reset the mine for performance reasons, when the mine resets blocks in the surface appear with the outdated table in mind
The positions blocks cant spawn in are stored using an array
The way blocks spawn is determined with the function below (sorry for messy code)
if p.Y<=0 then
local clone, main = nil
local rar = 0
for _,v in pairs(ores:GetChildren()) do
if v.Value>0 and v:GetAttribute("cave")==0 and v:GetAttribute("mindepth") <= math.abs(p.Y / 6) and v:GetAttribute("maxdepth") >= math.abs(p.Y / 6) and v:FindFirstChild("layer") == nil then
--print(v:FindFirstChild("layer"))
--print("depth: " .. math.abs(p.Y / 6))
local newrand = nil
if plr ~= nil --[[and v:GetAttribute("rarity")>7]] then
newrand = randomyeah:NextInteger(1,math.clamp(v.Value/plr.Settings.Luck.Value, 2, 10000000000))
else
newrand = randomyeah:NextInteger(1,math.clamp(v.Value, 2, 10000000000))
end
if newrand == 1 and v.Value>rar then
--print("depth: " .. math.abs(p.Y / 6))
clone = game.ReplicatedStorage.Ores[v.Name]
end
elseif v.Value==0 and v:GetAttribute("cave") == -id then
--print(v.Name)
main = game.ReplicatedStorage.Ores[v.Name]
elseif v.Value == 1 and v:GetAttribute("mindepth") <= math.abs(p.Y / 6) and v:GetAttribute("maxdepth") >= math.abs(p.Y / 6) and v:FindFirstChild("layer") then
--print(v.Name)
main = game.ReplicatedStorage.Ores[v.Name]
end
end
if cv then
for _,v in pairs(ores:GetChildren()) do
if v.Value>0 and v:GetAttribute("cave")==id and v:GetAttribute("mindepth") <= math.abs(p.Y / 6) and v:GetAttribute("maxdepth") >= math.abs(p.Y / 6) and v:FindFirstChild("layer") == nil then
--print(id)
local newrand = nil
if plr ~= nil and v:GetAttribute("rarity")>7 then
newrand = randomyeah:NextInteger(1,math.clamp(v.Value/plr.Settings.Luck.Value, 2, 10000000000))
else
newrand = randomyeah:NextInteger(1,math.clamp(v.Value, 2, 10000000000))
end
if newrand == 1 and v.Value>rar then
clone = game.ReplicatedStorage.Ores[v.Name]
end
elseif v:GetAttribute("offlayerValue")>0 and v:GetAttribute("offlayer")==id and v:FindFirstChild("layer") == nil then
local newrand = nil
if plr ~= nil and v:GetAttribute("rarity")>7 then
newrand = randomyeah:NextInteger(1,math.clamp(v:GetAttribute("offlayerValue")/plr.Settings.Luck.Value, 2, 10000000000))
else
newrand = randomyeah:NextInteger(1,math.clamp(v:GetAttribute("offlayerValue"), 2, 10000000000))
end
if newrand == 1 and v.Value>rar then
clone = game.ReplicatedStorage.Ores[v.Name]
end
end
end
end
when it comes to the mine resetting this is the code responsible
local function mineReset()
if firstReset == true then
firstReset = false
for x = -30,30,6 do
for z = -30,30,6 do
local c = choose(Vector3.new(x,0,z), nil, 0)
end
end
workspace.Part.Transparency = 1
workspace.Part.CanCollide = false
else
print("mine resetting in 30 seconds")
game.ReplicatedStorage.Effect:FireAllClients(nil, true)
wait(30)
print("resetting mine...")
workspace.Part.Transparency = 0
workspace.Part.CanCollide = true
for i,v in pairs(game.Players:GetPlayers()) do
v.Character.HumanoidRootPart.CFrame = CFrame.new(math.random(1,10),8,math.random(1,10))
end
task.wait(1)
for i,v in pairs(game.Workspace.Blocks:GetChildren()) do
blocks[v.Position] = nil
v:Destroy()
incr += 1
if incr % 500 == 0 then
wait()
end
end
for x = -30,30,6 do
for z = -30,30,6 do
local c = choose(Vector3.new(x,0,z), nil, 0)
end
end
workspace.Part.Transparency = 1
workspace.Part.CanCollide = false
end
end
if my logic is correct it seemingly should reset all blocks upon the mine resetting but it just ends up looking like this
as opposed to what it’s supposed to look like
I’ve tried going about many different ways on how to solve this but nothing really worked and I’m just stuck here
If anyone would like more details on different things I’ll gladly supply it