Rebirth Script
Key Required

Rebirth Script

[🏆GUILDS] Mining SimulatorMr_KatMr_Kat 252 views 837 executesUpdated Aug 15, 2026
Unrated
00
Lua Script•854 lines (29831 chars)
--// Mining Simulator 1 AutoRebirth by Mr_Kat
local localTime = os.clock()

local RunService = game:GetService("RunService")
local Players = game:GetService("Players")
local LocalPlayer = Players.LocalPlayer

do
    repeat task.wait() until game:IsLoaded()
    local playerGui = LocalPlayer:WaitForChild("PlayerGui")
    
    local defaultScreenGui = playerGui:FindFirstChild("ScreenGui")
    if defaultScreenGui then
        local loadingFrame = defaultScreenGui:FindFirstChild("LoadingFrame")
        while loadingFrame and loadingFrame.BackgroundTransparency == 0 do
            for _, connection in pairs(getconnections(loadingFrame.Quality.LowQuality.MouseButton1Down)) do
                connection:Fire()
            end
            RunService.Heartbeat:Wait()
        end
        
        -- Hide default game UI elements, including StatsFrame, without destroying them
        for _, child in ipairs(defaultScreenGui:GetChildren()) do
            if child.Name ~= "ClientScript" then
                if child:IsA("GuiObject") then
                    child.Visible = false
                end
            end
        end

        -- Continuously monitor and hide specific sidebar buttons or new popup elements when they appear
        defaultScreenGui.ChildAdded:Connect(function(child)
            if child.Name ~= "ClientScript" and child:IsA("GuiObject") then
                child.Visible = false
            end
        end)
    end
end

print("[Status] Initial loading checks executed successfully, all default game UI hidden.")

local function GetCharacterPrimaryPart()
    local character = LocalPlayer.Character or LocalPlayer.CharacterAdded:Wait()
    return character:WaitForChild("HumanoidRootPart", 5) or character:WaitForChild("PrimaryPart", 5)
end

local Character = GetCharacterPrimaryPart()

-- Apply Custom Tags on Character Load/Spawn
task.spawn(function()
    getgenv().Name = "Buddy"
    local character = LocalPlayer.Character or LocalPlayer.CharacterAdded:Wait()
    local head = character:WaitForChild("Head", 5)
    if head then
        local customTag = head:WaitForChild("CustomPlayerTag", 5)
        if customTag then
            if customTag:FindFirstChild("PlayerName") then
                customTag.PlayerName.Text = getgenv().Name
            end
            if customTag:FindFirstChild("MinerRank") then
                customTag.MinerRank.Text = "Touch some grass"
            end
        end
    end
    print("[Status] Custom tags check and application executed.")
end)

local WorldPresets = {
    Cyber = {
        SpawnName = "CyberSpawn", 
        SellName = "CyberSell",    
        SellPos = Vector3.new(58.525, 13.338, 30181.4), 
        MineX = 35.64487075805664, 
        MineZ = 30018.009765625,         
        SpawnZ = 30138,
    },
    Lava = {
        SpawnName = "LavaSpawn", 
        SellName = "LavaSell",    
        SellPos = Vector3.new(58.525, 13.338, 26365.4), 
        MineX = 30.212148666381836, 
        MineZ = 26202.228515625,         
        SpawnZ = 26322,
    }
}

local MapConfig = {
    -- Choose your world here: "Cyber" or "Lava"
    SelectedWorld = "Lava",

    MaxDepth = -1000,
    WalkY = 13.05,                        
    MineTopY = 10,                        
    ForcefieldX = 21,            
    ForcefieldY = 9.5,        
    RebirthCost = 10000000,

    -- Area sizes
    MiningAreaSize = Vector3.new(10, 10, 10), -- Used for the main RebirthLoop
    InitialDescentSize = Vector3.new(1, 1, 1), -- Used exclusively for the initial tunnel descent
}

-- Load dynamic world coordinates based on selection
local activeWorld = WorldPresets[MapConfig.SelectedWorld] or WorldPresets.Cyber
MapConfig.SpawnName = activeWorld.SpawnName
MapConfig.SellName = activeWorld.SellName
MapConfig.SellPos = activeWorld.SellPos
MapConfig.MineX = activeWorld.MineX
MapConfig.MineZ = activeWorld.MineZ
MapConfig.SpawnZ = activeWorld.SpawnZ

-- DO NOT CHANGE
local Config = {
    SellThreshold = 50000,                    
    InstantTeleportAfterSell = true,
    TeleportDelay = 0
}

-- Block Color Modifier Logic
local targetColor = Color3.fromRGB(0, 0, 0) -- Pure black
local blocksFolder = workspace:FindFirstChild("Blocks")

local function turnBlockBlack(part)
    if part:IsA("BasePart") then
        part.Color = targetColor
        part.Material = Enum.Material.SmoothPlastic -- Removes surface texture bump
        
        -- Remove any Decals or Texture objects mapped onto the block
        for _, child in ipairs(part:GetChildren()) do
            if child:IsA("Texture") or child:IsA("Decal") then
                child:Destroy()
            end
        end
    end
end

if blocksFolder then
    -- Apply to all existing blocks
    for _, descendant in ipairs(blocksFolder:GetDescendants()) do
        turnBlockBlack(descendant)
    end

    -- Automatically apply to newly spawned blocks as you dig
    blocksFolder.DescendantAdded:Connect(function(descendant)
        task.defer(turnBlockBlack, descendant)
    end)
    
    print("[Success] All blocks converted to black!")
else
    warn("[Error] 'Blocks' folder not found in Workspace.")
end

local PlayerGui = LocalPlayer:WaitForChild("PlayerGui")

local ScreenGui = Instance.new("ScreenGui")
ScreenGui.Name = "MiningDashboard"
ScreenGui.ResetOnSpawn = false
ScreenGui.Parent = PlayerGui

local MainFrame = Instance.new("Frame")
MainFrame.Name = "MainFrame"
MainFrame.Size = UDim2.new(0, 240, 0, 375)
MainFrame.Position = UDim2.new(0, 20, 0, 120)
MainFrame.BackgroundColor3 = Color3.fromRGB(20, 20, 30)
MainFrame.BorderSizePixel = 0
MainFrame.Parent = ScreenGui

local UICorner = Instance.new("UICorner")
UICorner.CornerRadius = UDim.new(0, 8)
UICorner.Parent = MainFrame

local UIStroke = Instance.new("UIStroke")
UIStroke.Color = Color3.fromRGB(80, 80, 120)
UIStroke.Thickness = 1.5
UIStroke.Parent = MainFrame

local Title = Instance.new("TextLabel")
Title.Size = UDim2.new(1, 0, 0, 34)
Title.BackgroundTransparency = 1
Title.Font = Enum.Font.GothamBold
Title.Text = "MINING & TRACKER"
Title.TextColor3 = Color3.fromRGB(220, 220, 255)
Title.TextSize = 15
Title.Parent = MainFrame

local function CreateStatRow(name, yPos)
    local Label = Instance.new("TextLabel")
    Label.Name = name
    Label.Size = UDim2.new(1, -20, 0, 28)
    Label.Position = UDim2.new(0, 10, 0, yPos)
    Label.BackgroundTransparency = 1
    Label.Font = Enum.Font.GothamBold
    Label.TextXAlignment = Enum.TextXAlignment.Left
    Label.TextColor3 = Color3.fromRGB(190, 190, 220)
    Label.TextSize = 14
    Label.Parent = MainFrame
    return Label
end

local BlocksLabel = CreateStatRow("BlocksLabel", 34)
local RebirthsLabel = CreateStatRow("RebirthsLabel", 62)
local TokensLabel = CreateStatRow("TokensLabel", 90)      
local DepthLabel = CreateStatRow("DepthLabel", 118)
local DepthCordsLabel = CreateStatRow("DepthCordsLabel", 146)

local leaderstats = LocalPlayer:WaitForChild("leaderstats")
local blocksMinedStat = leaderstats:WaitForChild("Blocks Mined")
local rebirthsStat = leaderstats:WaitForChild("Rebirths")
local tokensStat = leaderstats:FindFirstChild("Tokens") or leaderstats:FindFirstChild("Token")

local function FormatNumber(num)
    local formatted = tostring(num)
    while true do
        local k
        formatted, k = string.gsub(formatted, "^(-?%d+)(%d%d%d)", "%1,%2")
        if k == 0 then break end
    end
    return formatted
end

local function UpdateUI()
    BlocksLabel.Text = "Blocks Mined: " .. FormatNumber(blocksMinedStat.Value)
    RebirthsLabel.Text = "Rebirths: " .. FormatNumber(rebirthsStat.Value)
    if tokensStat then
        TokensLabel.Text = "Tokens: " .. FormatNumber(tokensStat.Value)
    else
        TokensLabel.Text = "Tokens: N/A"
    end
end

blocksMinedStat.Changed:Connect(UpdateUI)
rebirthsStat.Changed:Connect(UpdateUI)
if tokensStat then
    tokensStat.Changed:Connect(UpdateUI)
end
UpdateUI()

local TrackerContainer = Instance.new("Frame")
TrackerContainer.Name = "TrackerContainer"
TrackerContainer.Parent = MainFrame
TrackerContainer.BackgroundTransparency = 1
TrackerContainer.Position = UDim2.new(0, 10, 0, 180)
TrackerContainer.Size = UDim2.new(1, -20, 0, 185)

local TrackerLayout = Instance.new("UIListLayout")
TrackerLayout.Parent = TrackerContainer
TrackerLayout.SortOrder = Enum.SortOrder.LayoutOrder
TrackerLayout.VerticalAlignment = Enum.VerticalAlignment.Top
TrackerLayout.HorizontalAlignment = Enum.HorizontalAlignment.Center
TrackerLayout.Padding = UDim.new(0, 6)

local function CreateCard(name, height, order)
    local card = Instance.new("Frame")
    card.Name = name
    card.Parent = TrackerContainer
    card.BackgroundColor3 = Color3.fromRGB(25, 25, 35)
    card.BackgroundTransparency = 0.2
    card.Size = UDim2.new(1, 0, 0, height)
    card.LayoutOrder = order

    local corner = Instance.new("UICorner")
    corner.CornerRadius = UDim.new(0, 6)
    corner.Parent = card

    local stroke = Instance.new("UIStroke")
    stroke.Color = Color3.fromRGB(50, 50, 65)
    stroke.Transparency = 0.4
    stroke.Thickness = 1
    stroke.Parent = card

    return card
end

local CustomCard = CreateCard("CustomRow", 34, 1)

local TimeInput = Instance.new("TextBox")
TimeInput.Parent = CustomCard
TimeInput.BackgroundTransparency = 1
TimeInput.Position = UDim2.new(0.04, 0, 0, 0)
TimeInput.Size = UDim2.new(0.62, 0, 1, 0)
TimeInput.Font = Enum.Font.GothamBold
TimeInput.Text = ""
TimeInput.PlaceholderText = "Seconds..."
TimeInput.TextColor3 = Color3.fromRGB(240, 240, 250)
TimeInput.PlaceholderColor3 = Color3.fromRGB(120, 120, 135)
TimeInput.TextSize = 13
TimeInput.ClearTextOnFocus = false

local SetButton = Instance.new("TextButton")
SetButton.Name = "SetBtn"
SetButton.Parent = CustomCard
SetButton.BackgroundTransparency = 1
SetButton.Position = UDim2.new(0.68, 0, 0, 0)
SetButton.Size = UDim2.new(0.28, 0, 1, 0)
SetButton.Font = Enum.Font.GothamBold
SetButton.Text = "SET"
SetButton.TextColor3 = Color3.fromRGB(52, 199, 89)
SetButton.TextSize = 13

local PresetRow = Instance.new("Frame")
PresetRow.Name = "PresetRow"
PresetRow.Parent = TrackerContainer
PresetRow.BackgroundTransparency = 1
PresetRow.Size = UDim2.new(1, 0, 0, 34)
PresetRow.LayoutOrder = 2

local function CreatePresetBtn(name, text, orderOffset)
    local btnFrame = Instance.new("Frame")
    btnFrame.Name = name
    btnFrame.Parent = PresetRow
    btnFrame.BackgroundColor3 = Color3.fromRGB(25, 25, 35)
    btnFrame.BackgroundTransparency = 0.2
    btnFrame.Size = UDim2.new(0.48, 0, 1, 0)
    btnFrame.Position = UDim2.new(orderOffset, 0, 0, 0)

    local corner = Instance.new("UICorner")
    corner.CornerRadius = UDim.new(0, 6)
    corner.Parent = btnFrame

    local stroke = Instance.new("UIStroke")
    stroke.Color = Color3.fromRGB(50, 50, 65)
    stroke.Transparency = 0.4
    stroke.Thickness = 1
    stroke.Parent = btnFrame

    local btn = Instance.new("TextButton")
    btn.Parent = btnFrame
    btn.BackgroundTransparency = 1
    btn.Size = UDim2.new(1, 0, 1, 0)
    btn.Font = Enum.Font.GothamBold
    btn.Text = text
    btn.TextColor3 = Color3.fromRGB(210, 210, 225)
    btn.TextSize = 13
    return btn
end

local Min1Btn = CreatePresetBtn("Min1Btn", "1 MIN", 0)
local Min5Btn = CreatePresetBtn("Min5Btn", "5 MIN", 0.52)

local StartCard = CreateCard("StartCard", 38, 3)
StartCard.BackgroundColor3 = Color3.fromRGB(0, 113, 227)
StartCard.BackgroundTransparency = 0.1

local StartButton = Instance.new("TextButton")
StartButton.Parent = StartCard
StartButton.BackgroundTransparency = 1
StartButton.Size = UDim2.new(1, 0, 1, 0)
StartButton.Font = Enum.Font.GothamBold
StartButton.Text = "START TRACKING"
StartButton.TextColor3 = Color3.fromRGB(255, 255, 255)
StartButton.TextSize = 13

local StatusCard = CreateCard("StatusCard", 34, 4)
StatusCard.BackgroundColor3 = Color3.fromRGB(15, 15, 20)
StatusCard.BackgroundTransparency = 0.4

local StatusLabel = Instance.new("TextLabel")
StatusLabel.Parent = StatusCard
StatusLabel.BackgroundTransparency = 1
StatusLabel.Size = UDim2.new(1, 0, 1, 0)
StatusLabel.Font = Enum.Font.GothamBold
StatusLabel.Text = "Select time to begin"
StatusLabel.TextColor3 = Color3.fromRGB(180, 180, 195)
StatusLabel.TextSize = 12

local TrackerState = {
    Running = false,
    WaitTime = 0,
    StartBlocks = 0,
    StartRebirths = 0,
    ElapsedTime = 0,
    Stopping = false
}

local function GetTrackerStats()
    local blocks = blocksMinedStat.Value or 0
    local rebirths = rebirthsStat.Value or 0
    return blocks, rebirths
end

local function ResetTrackerVisuals()
    Min1Btn.TextColor3 = Color3.fromRGB(210, 210, 225)
    Min5Btn.TextColor3 = Color3.fromRGB(210, 210, 225)
    SetButton.TextColor3 = Color3.fromRGB(52, 199, 89)
end

local function ResetTrackerState()
    TrackerState.Running = false
    TrackerState.Stopping = false
    TrackerState.ElapsedTime = 0
    StartButton.Text = "START TRACKING"
    StartCard.BackgroundColor3 = Color3.fromRGB(0, 113, 227)
end

local function StartTracking()
    if TrackerState.WaitTime <= 0 then
        StatusLabel.Text = "⚠️ Select time first!"
        return
    end
    
    if TrackerState.Running then
        TrackerState.Stopping = true
        StatusLabel.Text = "Stopping..."
        return
    end
    
    TrackerState.Running = true
    TrackerState.Stopping = false
    TrackerState.ElapsedTime = 0
    
    StartButton.Text = "STOP"
    StartCard.BackgroundColor3 = Color3.fromRGB(255, 69, 58)
    StatusLabel.Text = "Starting in 3..."
    
    for i = 3, 1, -1 do
        if TrackerState.Stopping then ResetTrackerState(); StatusLabel.Text = "Cancelled"; return end
        StatusLabel.Text = "Starting in " .. i .. "..."
        task.wait(1)
    end
    
    if TrackerState.Stopping then ResetTrackerState(); StatusLabel.Text = "Cancelled"; return end

    TrackerState.StartBlocks, TrackerState.StartRebirths = GetTrackerStats()
    local remaining = TrackerState.WaitTime
    
    while remaining > 0 do
        if TrackerState.Stopping then break end
        StatusLabel.Text = "⏱️ Time Left: " .. remaining .. "s"
        task.wait(1)
        remaining = remaining - 1
        TrackerState.ElapsedTime = TrackerState.ElapsedTime + 1
    end
    
    local endBlocks, endRebirths = GetTrackerStats()
    local gainedBlocks = math.max(0, endBlocks - TrackerState.StartBlocks)
    local gainedRebirths = math.max(0, endRebirths - TrackerState.StartRebirths)
    
    StatusLabel.Text = string.format("B: %s | R: %s", FormatNumber(gainedBlocks), FormatNumber(gainedRebirths))
    ResetTrackerState()
end

Min1Btn.MouseButton1Click:Connect(function()
    if TrackerState.Running then return end
    ResetTrackerVisuals()
    if TrackerState.WaitTime == 60 then
        TrackerState.WaitTime = 0
    else
        TrackerState.WaitTime = 60
        Min1Btn.TextColor3 = Color3.fromRGB(52, 199, 89)
    end
end)

Min5Btn.MouseButton1Click:Connect(function()
    if TrackerState.Running then return end
    ResetTrackerVisuals()
    if TrackerState.WaitTime == 300 then
        TrackerState.WaitTime = 0
    else
        TrackerState.WaitTime = 300
        Min5Btn.TextColor3 = Color3.fromRGB(52, 199, 89)
    end
end)

SetButton.MouseButton1Click:Connect(function()
    if TrackerState.Running then return end
    ResetTrackerVisuals()
    local num = tonumber(TimeInput.Text)
    if num and num > 0 then
        TrackerState.WaitTime = num
        SetButton.TextColor3 = Color3.fromRGB(0, 199, 190)
        StatusLabel.Text = "Set to " .. num .. "s"
    else
        StatusLabel.Text = "⚠️ Invalid time"
    end
end)

StartButton.MouseButton1Click:Connect(function()
    task.spawn(StartTracking)
end)

local function GetInventoryAmount()
    local success, result = pcall(function()
        local statsFrame = LocalPlayer.PlayerGui.ScreenGui:FindFirstChild("StatsFrame")
        if statsFrame then
            local inventory = statsFrame:FindFirstChild("Inventory")
            if inventory and inventory:FindFirstChild("Amount") then
                local amtText = inventory.Amount.Text
                local amt = string.split(amtText, "/")[1]
                if amt then
                    return tonumber((amt:gsub(",", ""))) or 0
                end
            end
        end
        return 0
    end)
    return success and result or 0
end

-- Robust Remote Resolution
local Remote = nil
local function ResolveRemote()
    local screenGui = LocalPlayer:WaitForChild("PlayerGui"):WaitForChild("ScreenGui", 5)
    if screenGui then
        local clientScript = screenGui:WaitForChild("ClientScript", 5)
        if clientScript and getsenv and getupvalue then
            local success, env = pcall(getsenv, clientScript)
            if success and env and env.updatePasses then
                local upvalueSuccess, values = pcall(getupvalue, env.updatePasses, 8)
                if upvalueSuccess and type(values) == "table" and values["RemoteEvent"] then
                    return values["RemoteEvent"]
                end
            end
        end
    end

    local repStorage = game:GetService("ReplicatedStorage")
    local foundRemote = repStorage:FindFirstChild("Network") or repStorage:FindFirstChild("RemoteEvent") or repStorage:FindFirstChild("Events")
    if foundRemote and foundRemote:IsA("RemoteEvent") then
        return foundRemote
    end

    return nil
end

repeat
    Remote = ResolveRemote()
    if not Remote then task.wait(0.2) end
until Remote ~= nil
print("[Status] RemoteEvent successfully linked.")

local Collapse = false
local Counter = 0
local ScriptIsBroken = false

local vuAF = game:GetService("VirtualUser")
LocalPlayer.Idled:connect(function()
    vuAF:Button2Down(Vector2.new(0,0),workspace.CurrentCamera.CFrame)
    task.wait(0.5)
    vuAF:Button2Up(Vector2.new(0,0),workspace.CurrentCamera.CFrame)
end)

local CoinsAmount = LocalPlayer.leaderstats.Coins
local function GetCoinsAmount()
    local Amount = CoinsAmount.Value
    if type(Amount) == "string" then
        Amount = Amount:gsub(',', '')
    end
    return tonumber(Amount) or 0
end

if Remote and typeof(Remote) == "Instance" and Remote:IsA("RemoteEvent") then
    Remote.OnClientEvent:Connect(function()
        return nil
    end)
end

local function getCurrentHRP()
    local char = LocalPlayer.Character
    if char then
        return char:FindFirstChild("HumanoidRootPart")
    end
    return nil
end

task.spawn(function()
    while true do
        local hrp = getCurrentHRP()
        if hrp then
            local pos = hrp.Position
            local depthBlocks = math.floor((MapConfig.MineTopY - pos.Y) / 2)
            if depthBlocks < 0 then depthBlocks = 0 end
            DepthLabel.Text = "Depth: " .. FormatNumber(depthBlocks) .. " blocks"
            DepthCordsLabel.Text = string.format("Cords: %.1f, %.1f, %.1f", pos.X, pos.Y, pos.Z)
        else
            DepthLabel.Text = "Depth: N/A"
            DepthCordsLabel.Text = "Cords: N/A"
        end
        task.wait(0.2)
    end
end)

-- Current depth tracker initialized to mine top
local currentMiningY = MapConfig.MineTopY

local function returnToMiningPosition()
    local HumanoidRootPart = getCurrentHRP()
    if not HumanoidRootPart or not HumanoidRootPart.Parent then return end
    
    HumanoidRootPart.AssemblyLinearVelocity = Vector3.zero
    HumanoidRootPart.AssemblyAngularVelocity = Vector3.zero
    HumanoidRootPart.CFrame = CFrame.new(MapConfig.MineX, currentMiningY + 3.5, MapConfig.MineZ)
end

local function ExecuteInitialTunnel()
    game.Workspace.Gravity = 196
    local char = LocalPlayer.Character or LocalPlayer.CharacterAdded:Wait()
    local HumanoidRootPart = char:WaitForChild("HumanoidRootPart")
    local humanoid = char:WaitForChild("Humanoid")
    
    humanoid.WalkSpeed = 0
    humanoid.JumpPower = 0
    HumanoidRootPart.Anchored = true
    
    local part = Instance.new("Part", workspace)
    part.Name = "SafeSpawnPlatform"
    part.Anchored = true
    part.Size = Vector3.new(20, 1, 20)
    part.Material = Enum.Material.ForceField
    part.Position = Vector3.new(MapConfig.MineX, MapConfig.ForcefieldY - 1, MapConfig.SpawnZ)
    
    if Remote then Remote:FireServer("MoveTo", {{MapConfig.SpawnName}}) end
    task.wait(0.5)
    
    HumanoidRootPart.CFrame = CFrame.new(MapConfig.MineX, MapConfig.ForcefieldY + 2, MapConfig.SpawnZ)
    task.wait(0.5)
    
    HumanoidRootPart.Anchored = false
    while HumanoidRootPart.Position.Z > MapConfig.MineZ do
        HumanoidRootPart.AssemblyLinearVelocity = Vector3.zero
        HumanoidRootPart.AssemblyAngularVelocity = Vector3.zero
        HumanoidRootPart.CFrame = CFrame.new(Vector3.new(MapConfig.MineX, MapConfig.WalkY, HumanoidRootPart.Position.Z - 0.5))
        RunService.Heartbeat:Wait()
    end
    
    HumanoidRootPart.CFrame = CFrame.new(MapConfig.MineX, MapConfig.MineTopY, MapConfig.MineZ)
    
    if part then part:Destroy() end
    game.Workspace.Gravity = 1000
    print("[Status] Initial spawn and positioning checks executed.")

    local overlapParams = OverlapParams.new()
    overlapParams.FilterType = Enum.RaycastFilterType.Include
    overlapParams.FilterDescendantsInstances = {game.Workspace.Blocks}

    -- Phase 1: Accurate 1x1x1 Tunnel down to MaxDepth
    print("[Status] Starting initial 1x1x1 tunnel down to MaxDepth...")
    local tunnelBoxSize = Vector3.new(
        math.max(MapConfig.InitialDescentSize.X, 2), 
        4, 
        math.max(MapConfig.InitialDescentSize.Z, 2)
    )
    
    while HumanoidRootPart.Position.Y > MapConfig.MaxDepth do
        HumanoidRootPart.AssemblyLinearVelocity = Vector3.zero
        HumanoidRootPart.AssemblyAngularVelocity = Vector3.zero

        local checkCFrame = CFrame.new(MapConfig.MineX, HumanoidRootPart.Position.Y - 2, MapConfig.MineZ)
        local parts = workspace:GetPartBoundsInBox(checkCFrame, tunnelBoxSize, overlapParams)
        
        if #parts > 0 then
            for _, block in ipairs(parts) do
                if block:IsA("BasePart") then
                    if Remote then Remote:FireServer("MineBlock", {{block.Parent}}) end
                end
                RunService.Heartbeat:Wait()
            end
        else
            HumanoidRootPart.CFrame = HumanoidRootPart.CFrame - Vector3.new(0, 2, 0)
        end
        RunService.Heartbeat:Wait()
    end

    -- Phase 2: Clear layers completely per layer before descending
    print("[Status] Reached MaxDepth. Clearing layers thoroughly (full clearance per layer)...")
    local clearedLayers = 0
    local targetLayers = 3
    local totalBlocksCleared = 0
    local clearingBoxSize = Vector3.new(MapConfig.MiningAreaSize.X, 4, MapConfig.MiningAreaSize.Z)

    while clearedLayers < targetLayers do
        HumanoidRootPart.AssemblyLinearVelocity = Vector3.zero
        HumanoidRootPart.AssemblyAngularVelocity = Vector3.zero

        local checkCFrame = CFrame.new(MapConfig.MineX, HumanoidRootPart.Position.Y - 2, MapConfig.MineZ)
        local parts = workspace:GetPartBoundsInBox(checkCFrame, clearingBoxSize, overlapParams)
        
        if #parts > 0 then
            for _, block in ipairs(parts) do
                if block:IsA("BasePart") then
                    if Remote then Remote:FireServer("MineBlock", {{block.Parent}}) end
                    totalBlocksCleared = totalBlocksCleared + 1
                end
                RunService.Heartbeat:Wait()
            end
        else
            HumanoidRootPart.CFrame = HumanoidRootPart.CFrame - Vector3.new(0, 2, 0)
            clearedLayers = clearedLayers + 1
            print(string.format("[Status] Layer %d/%d fully cleared.", clearedLayers, targetLayers))
        end
        RunService.Heartbeat:Wait()
    end

    print(string.format("[Status] All initial layers cleared successfully! Total blocks mined during setup: %s", FormatNumber(totalBlocksCleared)))

    currentMiningY = HumanoidRootPart.Position.Y
    game.Workspace.Gravity = 196
    print(string.format("[Status] Initial clearance complete. Saved resume depth Y: %.1f", currentMiningY))
end

-- Run setup tunnel logic
ExecuteInitialTunnel()

local function RebirthLoop()
    local characterInstance = LocalPlayer.Character
    if not characterInstance or not characterInstance:FindFirstChild("Humanoid") then return end
    characterInstance.Humanoid.PlatformStand = true

    while not Collapse and not ScriptIsBroken do
        local hrp = getCurrentHRP()
        if not hrp then break end

        local Params = OverlapParams.new()
        Params.FilterType = Enum.RaycastFilterType.Include
        Params.FilterDescendantsInstances = {game.Workspace.Blocks}
        
        local parts = workspace:GetPartBoundsInBox(CFrame.new(MapConfig.MineX, hrp.Position.Y, MapConfig.MineZ), MapConfig.MiningAreaSize, Params)
 
        if parts[1] then
            for _, block in pairs(parts) do
                if Collapse or ScriptIsBroken then break end
                
                if block:IsA("BasePart") then
                    if block.Position.Y > (hrp.Position.Y - 2) then
                        currentMiningY = block.Position.Y
                    end
                    
                    hrp.AssemblyLinearVelocity = Vector3.zero
                    hrp.AssemblyAngularVelocity = Vector3.zero
                    hrp.CFrame = CFrame.new(MapConfig.MineX, currentMiningY + 3.5, MapConfig.MineZ)
                    
                    if Remote then Remote:FireServer("MineBlock", {{block.Parent}}) end
                end
 
                -- Continuous fast-sell loop using Heartbeat
                while GetInventoryAmount() >= Config.SellThreshold and not Collapse and not ScriptIsBroken do
                    hrp = getCurrentHRP()
                    if not hrp then break end
                    hrp.AssemblyLinearVelocity = Vector3.zero
                    hrp.AssemblyAngularVelocity = Vector3.zero
                    hrp.CFrame = CFrame.new(MapConfig.SellPos)
                    if Remote then Remote:FireServer("SellItems", {{}}) end
                    RunService.Heartbeat:Wait()
                end
 
                -- Continuous fast-rebirth spam loop using Heartbeat
                local RebirthsAmount = LocalPlayer.leaderstats.Rebirths
                if RebirthsAmount then
                    while GetCoinsAmount() >= (MapConfig.RebirthCost * (RebirthsAmount.Value + 1)) and not Collapse and not ScriptIsBroken do
                        if Remote then Remote:FireServer("Rebirth", {{}}) end
                        RunService.Heartbeat:Wait()
                    end
                end
 
                if Config.TeleportDelay > 0 then
                    task.wait(Config.TeleportDelay)
                end

                hrp = getCurrentHRP()
                if hrp then
                    if Config.InstantTeleportAfterSell then
                        hrp.CFrame = CFrame.new(MapConfig.MineX, currentMiningY + 3.5, MapConfig.MineZ)
                    else
                        returnToMiningPosition()
                    end
                end
            end
        else
            if not Collapse and not ScriptIsBroken then
                currentMiningY = currentMiningY - 2
                hrp.CFrame = CFrame.new(MapConfig.MineX, currentMiningY + 3.5, MapConfig.MineZ)
            end
        end
        RunService.Heartbeat:Wait()
    end 
end
 
game.Workspace.Collapsed.Changed:connect(function()
    if game.Workspace.Collapsed.Value == true then
        print("[Status] Collapse event detected, initiating safe recovery...")
        Collapse = true
        
        local function setUIElementsVisibility(visible)
            pcall(function()
                local screenGui = LocalPlayer.PlayerGui:FindFirstChild("ScreenGui")
                if screenGui then
                    local mainButtons = screenGui:FindFirstChild("MainButtons")
                    if mainButtons then
                        for _, childName in ipairs({"MiningPass", "Shop", "Index", "Surface"}) do
                            local btn = mainButtons:FindFirstChild(childName)
                            if btn then btn.Visible = hidden end
                        end
                        local invMain = mainButtons:FindFirstChild("InventoryFrame")
                        if invMain then invMain.Visible = hidden end
                    end
                    local invGui = screenGui:FindFirstChild("InventoryFrame")
                    if invGui then invGui.Visible = hidden end
                end
            end)
        end

        setUIElementsVisibility(false)

        local hrp = getCurrentHRP()
        if hrp then
            hrp.Anchored = true
            hrp.AssemblyLinearVelocity = Vector3.zero
            hrp.AssemblyAngularVelocity = Vector3.zero
        end

        local char = LocalPlayer.Character
        if char and char:FindFirstChild("Humanoid") then
            char.Humanoid.PlatformStand = false
            char.Humanoid.WalkSpeed = 0
            char.Humanoid.JumpPower = 0
        end

        task.wait(0.2)
        
        ExecuteInitialTunnel()

        task.spawn(function()
            task.wait(3)
            setUIElementsVisibility(true)
        end)

        Counter = 0
        Collapse = false
        task.spawn(RebirthLoop)
    end
end)
 
coroutine.wrap(function()
    while true do
        task.wait(1)
        Counter += 1
        if Counter >= 10 then
            if not ScriptIsBroken and not Collapse then
                ScriptIsBroken = true
                task.wait(0.2)
                
                returnToMiningPosition()
                
                Counter = 0
                ScriptIsBroken = false
                task.spawn(RebirthLoop)
            else
                Counter = 0
            end
        end
    end
end)()
 
task.spawn(RebirthLoop)
print("[Status] All setup procedures and checks have completely executed.")

Features & Information

For mining simulator 1

Community Comments (0)

No comments yet for this script.

More Scripts for [🏆GUILDS] Mining Simulator