local replicatedStorage = game:GetService("ReplicatedStorage") local events = replicatedStorage:WaitForChild("Events") local blocksFolder = workspace:WaitForChild("Main"):WaitForChild("Blocks") local players = game:GetService("Players") local localPlayer = players.LocalPlayer local getEnvironment = function() if not genv and type(getgenv) == "function" then genv = getgenv() elseif not genv then genv = {} _G.genv = genv end return genv end local env = getEnvironment() _G.AutoMining = false local activeTask = nil local locationMonitorTask = nil local lastDetectedLocation = nil local function getPlayerPosition() if localPlayer.Character and localPlayer.Character:FindFirstChild("HumanoidRootPart") then return localPlayer.Character.HumanoidRootPart.Position end return Vector3.new(0, 0, 0) end local function detectMiningID() local playerCharacter = workspace:FindFirstChild(localPlayer.Name) local activePickaxeName = nil if playerCharacter then for _, tool in pairs(playerCharacter:GetChildren()) do if tool:IsA("Tool") and string.find(tool.Name, "Pickaxe") then activePickaxeName = tool.Name print("Player is currently using: " .. activePickaxeName) break end end end if activePickaxeName and localPlayer:FindFirstChild("Inventory") then local pickaxe = localPlayer.Inventory:FindFirstChild(activePickaxeName) if pickaxe then local id = pickaxe:GetAttribute("ID") if id then print("Found ID for active pickaxe " .. activePickaxeName .. ": " .. id) return id end end end if localPlayer:FindFirstChild("Inventory") then for _, item in pairs(localPlayer.Inventory:GetChildren()) do if string.find(item.Name, "Pickaxe") then local id = item:GetAttribute("ID") if id then print("Found pickaxe ID in Inventory." .. item.Name .. ": " .. id) return id end end end end local character = localPlayer.Character local backpack = localPlayer:FindFirstChild("Backpack") local toolsList = {} if character then for _, tool in pairs(character:GetChildren()) do if tool:IsA("Tool") then table.insert(toolsList, tool) end end end if backpack then for _, tool in pairs(backpack:GetChildren()) do if tool:IsA("Tool") then table.insert(toolsList, tool) end end end for _, tool in pairs(toolsList) do if tool:FindFirstChild("ToolSettings") and tool.ToolSettings:FindFirstChild("pickaxeid") then print("Found pickaxeid in ToolSettings: " .. tool.ToolSettings.pickaxeid.Value) return tool.ToolSettings.pickaxeid.Value end if tool:GetAttribute("pickaxeid") then print("Found pickaxeid in tool attributes: " .. tool:GetAttribute("pickaxeid")) return tool:GetAttribute("pickaxeid") end for _, desc in pairs(tool:GetDescendants()) do if desc:IsA("ValueBase") and (string.lower(desc.Name):find("pickaxe") or string.lower(desc.Name):find("id")) then print("Found potential pickaxe ID in " .. desc:GetFullName() .. ": " .. desc.Value) return desc.Value end if desc:IsA("ModuleScript") or desc:IsA("LocalScript") then for attrName, attrValue in pairs(desc:GetAttributes()) do if typeof(attrValue) == "number" and string.lower(attrName):find("pickaxe") then print("Found pickaxe ID in script attributes: " .. attrValue) return attrValue end end end end end if character then for _, v in pairs(character:GetDescendants()) do if v:IsA("ValueBase") and string.lower(v.Name):find("pickaxe") then if typeof(v.Value) == "number" and v.Value > 1000000 then print("Found pickaxe ID in character: " .. v.Value) return v.Value end end end end local lastKnownID = 1747282970 print("Could not detect pickaxe ID automatically, using last known working ID: " .. lastKnownID) return lastKnownID end if not env.MiningID then env.MiningID = detectMiningID() end _G.SetMiningID = function(id) if type(id) == "number" then env.MiningID = id print("Mining ID manually set to: " .. id) else print("Invalid mining ID. Please provide a number.") end end local locationOreMap = { ["Coal"] = "Coal Ore", ["Copper"] = "Copper Ore", ["Iron"] = "Iron Ore", ["Gold"] = "Gold Ore", ["Sapphire"] = "Sapphire Ore", ["Ruby"] = "Ruby Ore", ["Mercury"] = nil, ["Venus"] = nil, ["Mars"] = nil, ["Jupiter"] = nil, ["Saturn"] = nil, ["Neptune"] = nil, ["Pluto"] = nil, ["Moon"] = nil, ["Asteroid"] = nil, ["Callisto"] = nil, ["Galaxy"] = nil, ["Nebula"] = nil, ["Cosmic"] = nil, ["Amethystia"] = "Amethyst Ore", ["Aetherium"] = "Aetherium Ore", ["Crystium"] = "Crystal Ore", ["Diamora"] = "Diamond Ore", ["Emeralda"] = "Emerald Ore", ["Luminite"] = "Luminite Ore", ["Opalthia"] = "Opal Ore", ["Shadowlum"] = "Shadow Ore", ["Stellarium"] = "Stellar Ore", ["Volcanium"] = "Volcanic Ore", ["Frost"] = "Ice Ore" } local function getCurrentOreType() local location = nil if localPlayer:FindFirstChild("CurrentLocation") then location = localPlayer.CurrentLocation.Value end local function detectOreInCurrentLocation() local oreTypes = {} for _, block in ipairs(blocksFolder:GetChildren()) do if block.Name:find("Ore") then oreTypes[block.Name] = true end end local availableOres = {} for oreName, _ in pairs(oreTypes) do table.insert(availableOres, oreName) end if #availableOres > 0 then return availableOres[1] end return nil end if location and locationOreMap[location] then return locationOreMap[location] end if location or not locationOreMap[location] then local detectedOre = detectOreInCurrentLocation() if detectedOre then if location then locationOreMap[location] = detectedOre end return detectedOre end end local playerPos = getPlayerPosition() local closestBlock = nil local shortestDistance = math.huge for _, block in ipairs(blocksFolder:GetChildren()) do if block.Name:find("Ore") then local blockPos = block:IsA("BasePart") and block.Position or (block:FindFirstChild("Position") and block.Position.Value) if blockPos then local distance = (blockPos - playerPos).Magnitude if distance < shortestDistance then shortestDistance = distance closestBlock = block end end end end if closestBlock then return closestBlock.Name end return nil end local function stopAutoMining() _G.AutoMining = false if activeTask then task.cancel(activeTask) activeTask = nil print("Mining task canceled") end end local function startAutoMining() if activeTask then return end _G.AutoMining = true activeTask = task.spawn(function() while true do if not _G.AutoMining then print("Auto mining disabled, stopping task") activeTask = nil break end local oreType = getCurrentOreType() if oreType then local playerPos = getPlayerPosition() local oreBlocks = {} for _, block in ipairs(blocksFolder:GetChildren()) do if block.Name == oreType then local blockPos = block:FindFirstChild("Position") and block.Position.Value or (block:IsA("BasePart") and block.Position or (block:FindFirstChild("PrimaryPart") and block.PrimaryPart.Position or nil)) if blockPos then local distance = (blockPos - playerPos).Magnitude table.insert(oreBlocks, {block = block, distance = distance}) else if block:FindFirstChild("CFrame") then local distance = (block.CFrame.Position - playerPos).Magnitude table.insert(oreBlocks, {block = block, distance = distance}) else table.insert(oreBlocks, {block = block, distance = math.huge}) end end end end if #oreBlocks == 0 then task.wait(1) continue end table.sort(oreBlocks, function(a, b) return a.distance < b.distance end) local blockLimit = math.min(10, #oreBlocks) for i = 1, blockLimit do if not _G.AutoMining then break end local currentOre = getCurrentOreType() if currentOre ~= oreType then break end local blockData = oreBlocks[i] local block = blockData.block local args = { block, env.MiningID } local hitCount = 0 local maxHits = 8 local hitDelay = 0.02 while hitCount < maxHits and block and block.Parent do if not _G.AutoMining then break end for burstHit = 1, 2 do events:WaitForChild("DamageBlock"):FireServer(unpack(args)) end hitCount = hitCount + 2 task.wait(hitDelay) if not block.Parent then break end end task.wait(0.04) end else task.wait(1.5) end task.wait(0.15) end end) end local function startLocationMonitor() if locationMonitorTask then return end locationMonitorTask = task.spawn(function() while true do local location = nil if localPlayer:FindFirstChild("CurrentLocation") then location = localPlayer.CurrentLocation.Value end if location ~= lastDetectedLocation then lastDetectedLocation = location if _G.AutoMining then if activeTask then task.cancel(activeTask) activeTask = nil end task.wait(0.5) startAutoMining() end end task.wait(1) end end) end local lastKnownPickaxeName = nil local pickaxeCheckTask = nil local function startPickaxeMonitor() if pickaxeCheckTask then return end pickaxeCheckTask = task.spawn(function() while true do local playerCharacter = workspace:FindFirstChild(localPlayer.Name) local currentPickaxeName = nil if playerCharacter then for _, tool in pairs(playerCharacter:GetChildren()) do if tool:IsA("Tool") and string.find(tool.Name, "Pickaxe") then currentPickaxeName = tool.Name break end end end if currentPickaxeName and currentPickaxeName ~= lastKnownPickaxeName then lastKnownPickaxeName = currentPickaxeName if _G.AutoMining then local newMiningID = detectMiningID() if newMiningID and newMiningID ~= env.MiningID then env.MiningID = newMiningID print("Pickaxe changed! Updated mining ID to: " .. newMiningID) end end end task.wait(1) end end) end _G.StopMining = function() stopAutoMining() end _G.StartMining = function() if not _G.AutoMining then _G.AutoMining = true startAutoMining() end end _G.ToggleAutoMine = function() if _G.AutoMining then _G.StopMining() else _G.StartMining() end return _G.AutoMining end if not _G.scriptLoaded then _G.scriptLoaded = true print("Pixel Prisons mining script loaded - brought to you by oyw / theboywhocried") end startLocationMonitor() startPickaxeMonitor() startAutoMining() if _G.AutoMining then startAutoMining()end