I was scripting some extra stuff into a mining system I made for my game, but all the sudden it broke and it starts putting blocks in places where they shouldn’t be, and I don’t know what’s going wrong because I changed nothing for this to happen as far as I’m aware.
Here’s the code if anyone could help I’d appreciate it.
local ReplicatedStorage = game:GetService("ReplicatedStorage")
local ServerStorage = game:GetService("ServerStorage")
local POSITIONS = {
Vector3.new(6, 0, 0),
Vector3.new(-6, 0, 0),
Vector3.new(0, 6, 0),
Vector3.new(0, -6, 0),
Vector3.new(0, 0, 6),
Vector3.new(0, 0, -6),
}
local Layers = {
ServerStorage.LayerBlocks.Stone,
ServerStorage.LayerBlocks.Limestone,
ServerStorage.LayerBlocks.Granite,
ServerStorage.LayerBlocks.Diorite,
ServerStorage.LayerBlocks.Sandstone,
ServerStorage.LayerBlocks.Obsidian,
ServerStorage.LayerBlocks["Cracked Lava"],
ServerStorage.LayerBlocks.Magma,
ServerStorage.LayerBlocks.Bedrock,
ServerStorage.LayerBlocks["Compressed Lava"],
ServerStorage.LayerBlocks["Unbreakable Steel"]
}
local OreTable = {}
for Index, Inst in ipairs(ServerStorage.Ores:GetChildren()) do
if Inst:IsA("Part") then
table.insert(OreTable, {oBlock = Inst, chance = Inst.Chance.Value})
end
end
local function generateOres(position, depth)
if not position then
return
end
local generated = workspace.Generated
for _, offset in ipairs(POSITIONS) do
local newPosition = position + offset
if newPosition.Y > 0 then
continue
end
if generated:FindFirstChild(tostring(newPosition)) then
continue
end
local random = math.random(1, #OreTable)
local willSpawn = math.random(1, OreTable[random].chance)
if willSpawn == 1 then
ore = OreTable[random].oBlock:Clone()
if OreTable[random].chance >= 1000000000 then
ReplicatedStorage.EventText:FireAllClients("Mythical")
ReplicatedStorage.Sounds.Unim:Play()
end
else
if depth == 0 then
ore = Layers[1]:Clone()
else
ore = Layers[math.ceil(depth / 1000)]:Clone()
end
end
ore.Position = newPosition
ore.Parent = workspace.Cubes
local value = Instance.new("Vector3Value")
value.Value = newPosition
value.Name = tostring(newPosition)
value.Parent = generated
end
end
local generated = workspace.Generated
for _, cube in ipairs(workspace.Cubes:GetChildren()) do
if cube:IsA("Part") then
local value = Instance.new("Vector3Value")
value.Value = cube.Position
value.Name = tostring(cube.Position)
value.Parent = generated
end
end
ReplicatedStorage.BlockGen.OnServerEvent:Connect(function(_, rPart)
generateOres(rPart.Position, math.abs(rPart.CFrame.Y / 6))
rPart:Destroy()
end)