I'm currently working solo on a mining simulator game. Everything went smooth in the development at first until I encountered this problem. I was not able to solve this problem for over 3 days and it have been denying me to have any further development.
The issue that I'm having can be quite complicated. I'll try to provide as much information as possible and explain it as best as I can.
So, when a player mines a block. New blocks will be generated in all directions. Their coord will be logged so generated coordinates won't be regenerated. However, there is something wrong with the register process or the reading process. Allowing generated coordinates to be regenerated. I can't find anything wrong in my script.
Here's my script, (Only the related portions)
local mine = workspace:WaitForChild("Mine")
--Modules
local layerModule = require(rep.Modules:WaitForChild("LayerModule"))
local oreModule = require(rep.Modules:WaitForChild("OreModule"))
--Tables
local generatedBlocks = {Vector3.new(0, 0, 0), Vector3.new(0, 1, 0))
local mineOreEvent = rep.Remotes:WaitForChild("MineOreEvent")
local getPlayerZoneFunc = rep.Remotes:WaitForChild("GetPlayerZoneFunc")
local function checkOrePosAvailability(orePos) -- see if a position is already generated or not
local bool
for i,v in pairs(generatedBlocks) do
if orePos == v then
bool = false
break
else bool = true
end
end
print(bool)
if (orePos.X > 24 or orePos.X < 0 or orePos.Z > 24 or orePos.Z < 24) and orePos.Y == -25 then
bool = "bedrock"
end
return bool
end
local function getMaxBlock() -- for remote function
return maximumBlocks
end
local function generateBlockAtPos(orePos, oldOre, moveVector)
local blockLayer, layerInfo = layerModule.findLayer(orePos.Y)
local randomOreForLayer = oreModule.getRandomOreForLayer(blockLayer)
local clonedBlock = serverStorage.Blocks:FindFirstChild(randomOreForLayer):Clone()
local newOrePosValue = Instance.new("Vector3Value")
newOrePosValue.Name = "OrePos"
newOrePosValue.Value = orePos + moveVector
newOrePosValue.Parent = clonedBlock
local newOreTypeValue = Instance.new("StringValue")
newOreTypeValue.Name = "OreType"
newOreTypeValue.Value = clonedBlock.Name
newOreTypeValue.Parent = clonedBlock
clonedBlock.Position = oldOre.Position + (moveVector * oldOre.Size.X)
clonedBlock.Color = layerInfo.color
table.insert(generatedBlocks, #generatedBlocks + 1, newOrePosValue.Value)
clonedBlock.Parent = mine
end
local function generateBedrockAtPos(orePos, oldOre, moveVector)
local clonedBlock = serverStorage.Blocks:FindFirstChild("Bedrock"):Clone()
local newOrePosValue = Instance.new("Vector3Value")
newOrePosValue.Name = "OrePos"
newOrePosValue.Value = orePos + moveVector
newOrePosValue.Parent = clonedBlock
local newOreTypeValue = Instance.new("StringValue")
newOreTypeValue.Name = "OreType"
newOreTypeValue.Value = clonedBlock.Name
newOreTypeValue.Parent = clonedBlock
clonedBlock.Position = oldOre.Position + (moveVector * oldOre.Size.X)
table.insert(generatedBlocks, #generatedBlocks + 1, newOrePosValue.Value)
clonedBlock.Parent = mine
end
--Events
mineOreEvent.OnServerEvent:Connect(function(plr, ore)
local oreType = ore:FindFirstChild("OreType").Value
local orePos = ore:FindFirstChild("OrePos").Value
local newPos = orePos
-- generate +X block
newPos = orePos + Vector3.new(1, 0, 0)
local PXAvailability = checkOrePosAvailability(newPos)
print(PXAvailability, newPos)
if PXAvailability == true then
generateBlockAtPos(newPos, ore, Vector3.new(1, 0, 0))
elseif PXAvailability == "bedrock" then
generateBedrockAtPos(newPos, ore, Vector3.new(1, 0, 0))
end
-- generate -X block
newPos = orePos - Vector3.new(1, 0, 0)
local MXAvailability = checkOrePosAvailability(newPos)
print(MXAvailability, newPos)
if MXAvailability == true then
generateBlockAtPos(newPos, ore, Vector3.new(-1, 0, 0))
elseif MXAvailability == "bedrock" then
generateBedrockAtPos(newPos, ore, Vector3.new(-1, 0, 0))
end
-- generate +Y block
newPos = orePos + Vector3.new(0, 1, 0)
local PYAvailability = checkOrePosAvailability(newPos)
print(PYAvailability, newPos)
if PYAvailability == true then
generateBlockAtPos(newPos, ore, Vector3.new(0, 1, 0))
elseif PYAvailability == "bedrock" then
generateBedrockAtPos(newPos, ore, Vector3.new(0, 1, 0))
end
-- generate -Y block
newPos = orePos - Vector3.new(0, 1, 0)
local MYAvailability = checkOrePosAvailability(newPos)
print(MYAvailability, newPos)
if MYAvailability == true then
generateBlockAtPos(newPos, ore, Vector3.new(0, -1, 0))
elseif MYAvailability == "bedrock" then
generateBedrockAtPos(newPos, ore, Vector3.new(0, -1, 0))
end
-- generate +Z block
newPos = orePos + Vector3.new(0, 0, 1)
local PZAvailability = checkOrePosAvailability(newPos)
print(PZAvailability, newPos)
if PZAvailability == true then
generateBlockAtPos(newPos, ore, Vector3.new(0, 0, 1))
elseif PZAvailability == "bedrock" then
generateBedrockAtPos(newPos, ore, Vector3.new(0, 0, 1))
end
-- generate -Z block
newPos = orePos - Vector3.new(0, 0, 1)
local MZAvailability = checkOrePosAvailability(newPos)
print(MZAvailability, newPos)
if MZAvailability == true then
generateBlockAtPos(newPos, ore, Vector3.new(0, 0, -1))
elseif MZAvailability == "bedrock" then
generateBedrockAtPos(newPos, ore, Vector3.new(0, 0, -1))
end
ore:Destroy()
end)
The script is organized and formatted in the real script but because I copied and pasted it, it's not formatted.
Here's the problem I'm facing in a video: Click me to view the video
I'm 100% sure that there is nothing wrong with the pickaxe. I've debugged it and checked everything and confirmed that the pickaxe has nothing to do with this issue.
If you can solve my problem, a million thanks.
Sincerely, TheRobloxPlayer2509
