So I was working on a system to respawn ores upon them being “deleted” (when an ore gets mined, their parent becomes a folder inside of server storage), but I have found an issue with my current system that ruins the game. When you try to mine one ore, then while that ore is respawning, you mine another ore, what happens is the second ore you mined will never respawn, the reason why this is happening is because of a debounce inside the respawning script, but if I remove that, the respawning becomes super glitchy for some reason.
Server script inside of ServerScriptService:
local db = false
while wait(3) do
for _,ore in pairs(workspace.ActiveOres:GetChildren()) do
ore:GetPropertyChangedSignal("Parent"):Connect(function()
for _,spawnBlock in pairs(workspace.SpawnBlocks:GetChildren()) do
if spawnBlock.Position == ore.Position then
local ores = game.ServerStorage.OreFolder:GetChildren()
local randomOre = ores[math.random(1, #ores)]
local clonedOre = randomOre:Clone()
coroutine.wrap(function()
if not db then
db = true
print(clonedOre.Name)
task.wait(clonedOre.SpawnDelay.Value)
clonedOre.Parent = workspace.ActiveOres
clonedOre.Position = spawnBlock.Position
db = false
end
end)()
end
end
end)
end
end
Any help is appreciated!