Recently I've been trying to make a block generation system similar to Mining Simulator's for a game. The idea of the code is to make blocks spawn around a block that was mined but obviously not spawn them where blocks already are. To do this I save the position of the blocks already existing, ones that are mined, and ones that are made. But the problem I run into is that the code constantly ignores the fact they're not supposed to spawn there and does it anyway.
local ServerStorage = game:GetService("ServerStorage")
local blockData = ServerStorage:WaitForChild("blockData")
function BackTrack(Target,Pos)
Target.Parent = workspace.Mineable
Target.CFrame = Pos
if blockData:FindFirstChild(tostring(Target.CFrame)) then
Target:Destroy()
end
Instance.new("Folder",blockData).Name = tostring(Target.CFrame)
end
function CreateBlocks(Target)
local bpos = Target.CFrame
Instance.new("Folder",blockData).Name = tostring(bpos)
spawn(function() BackTrack(ReplicatedStorage.Blocks.Dirt.Block:Clone(),CFrame.new(bpos.X,bpos.Y-7,bpos.Z)) end)
spawn(function() BackTrack(ReplicatedStorage.Blocks.Dirt.Block:Clone(),CFrame.new(bpos.X,bpos.Y,bpos.Z+7)) end)
spawn(function() BackTrack(ReplicatedStorage.Blocks.Dirt.Block:Clone(),CFrame.new(bpos.X,bpos.Y,bpos.Z-7)) end)
spawn(function() BackTrack(ReplicatedStorage.Blocks.Dirt.Block:Clone(),CFrame.new(bpos.X+7,bpos.Y,bpos.Z)) end)
spawn(function() BackTrack(ReplicatedStorage.Blocks.Dirt.Block:Clone(),CFrame.new(bpos.X-7,bpos.Y,bpos.Z)) end)
spawn(function() BackTrack(ReplicatedStorage.Blocks.Dirt.Block:Clone(),CFrame.new(bpos.X,bpos.Y+7,bpos.Z)) end)
end

2 comments
Maybe, you should check the CFrame of the "mined block", if it exist then don't spawn block on that.
Already attempted that, same problem.