Auto Farm
Key Required

Auto Farm

Treasure Hunt SimulatorJustShareJustShare 8.5K views 487 executesUpdated Jan 30, 2025
4.0/ 5(5 votes)
4180% Positive
Lua Scriptβ€’567 lines (20351 chars)
---------- [ Library ] ----------
local Library = loadstring(game:HttpGet("https://pastebin.com/raw/b5QLVFiM"))()

---------- [ Window ] ----------
local Window = Library:CreateWindow('JustShare - Hub')

---------- [ Create Tab ] ----------
local Tab = {
    Home = Window:addTab('β€’Home + Settings'),
    ESP = Window:addTab('β€’Esp'),
}

---------- [ Home Tab Section ] ----------
local Home_Right = Tab.Home:addSection()
local Main_Home = Home_Right:addMenu("#Home")

---------- [ Variables ] ----------
local Farm = false
local Rebirth = false
local IsSelling = false
local AutoFarmAI = false
local ESPEnabled = false
local FarmPaused = false
local XRayEnabled = false
local AutoSellEnabled = false
local ESPPlayerEnabled = false
local VisualEffectsEnabled = true
local CurrentChest = nil
local FarmingSpeed = 0.001  -- Mengatur farming speed menjadi 0.001
local PathfindingService = game:GetService("PathfindingService")
local UserInputService = game:GetService("UserInputService")
local VirtualInputManager = game:GetService("VirtualInputManager")
local XRayTransparency = 0.2
local PlayerHighlights = {}
local ChestHighlights = {}

---------- [ Sell Function ] ----------
local function Sell()
    if IsSelling then return end
    IsSelling = true

    local OldPos = game.Players.LocalPlayer.Character.HumanoidRootPart.CFrame
    game.Players.LocalPlayer.Character.HumanoidRootPart.CFrame = CFrame.new(3, 10, -160)
    wait(0.1)
    game.ReplicatedStorage.Events.AreaSell:FireServer()
    wait(0.1)

    game.Players.LocalPlayer.Character.HumanoidRootPart.CFrame = OldPos
    game:GetService("StarterGui"):SetCore("SendNotification", {
        Title = "Success!",
        Text = "Sand sold successfully!",
        Duration = 5,
    })

    IsSelling = false
end

---------- [ Auto Farm Loop ] ----------
local function AutoFarmLoop()
    while Farm do
        if FarmPaused then
            wait(0.1)
        else
            -- Memastikan tool ada di tangan
            local tool = game.Players.LocalPlayer.Character:FindFirstChildOfClass("Tool") or 
                         game.Players.LocalPlayer.Backpack:FindFirstChildOfClass("Tool")

            -- Pastikan tool tersedia sebelum melanjutkan
            if not tool then
                game:GetService("StarterGui"):SetCore("SendNotification", {
                    Title = "Error!",
                    Text = "No tool found! Disabling Auto Farm.",
                    Duration = 5,
                })
                Farm = false
                return
            elseif not game.Players.LocalPlayer.Character:FindFirstChildOfClass("Tool") then
                game.Players.LocalPlayer.Character.Humanoid:EquipTool(tool)
                wait(0.1)
            end

            -- Fokuskan posisi karakter hanya pada chest yang sedang di-farm
            if CurrentChest and CurrentChest.Parent then
                local humanoidRootPart = game.Players.LocalPlayer.Character.HumanoidRootPart
                local targetPosition = CurrentChest.Position

                -- Pindahkan karakter ke chest dengan kecepatan lebih tinggi
                if (humanoidRootPart.Position - targetPosition).Magnitude > 0.5 then
                    humanoidRootPart.CFrame = CFrame.new(targetPosition)
                end

                tool.RemoteClick:FireServer(CurrentChest)
                wait(FarmingSpeed)

                -- Cek apakah Backpack penuh dan jual otomatis jika perlu
                if AutoSellEnabled and game.Players.LocalPlayer.PlayerGui.Gui.Popups.BackpackFull.Visible then
                    FarmPaused = true
                    Sell()
                    FarmPaused = false
                end
            else
                -- Jika Chest tidak ditemukan, lakukan pencarian chest baru
                CurrentChest = nil
                for _, v in pairs(game.Workspace.SandBlocks:GetChildren()) do
                    if not Farm then break end
                    if v:FindFirstChild("Chest") then
                        CurrentChest = v
                        v.CanCollide = false
                        local character = game.Players.LocalPlayer.Character
                        if character then
                            -- Fokuskan posisi karakter pada chest baru
                            local humanoidRootPart = game.Players.LocalPlayer.Character.HumanoidRootPart
                            local targetPosition = v.Position
                            
                            -- Pindahkan posisi karakter hanya jika diperlukan
                            if (humanoidRootPart.Position - targetPosition).Magnitude > 0.5 then
                                humanoidRootPart.CFrame = CFrame.new(targetPosition)
                            end

                            tool.RemoteClick:FireServer(v)
                            wait(0.05)
                        end
                        break
                    end
                end
            end
        end
        wait(0.05) 
    end
end

---------- [ Toggling Features ] ----------
-- Auto Farm Toggle
Main_Home:addToggle('Auto Farm', false, function(state)
    Farm = state
    if state then
        -- Cek apakah tool sudah ada di karakter
        local tool = game.Players.LocalPlayer.Character:FindFirstChildOfClass("Tool")
        if not tool then
            tool = game.Players.LocalPlayer.Backpack:FindFirstChildOfClass("Tool")
        end
        
        if not tool then
            game:GetService("StarterGui"):SetCore("SendNotification", {
                Title = "Error!",
                Text = "No tool found! Auto Farm disabled.",
                Duration = 5,
            })
            Farm = false
            return
        end

        if not game.Players.LocalPlayer.Character:FindFirstChildOfClass("Tool") then
            game.Players.LocalPlayer.Character.Humanoid:EquipTool(tool)
            wait(0.1)
        end

        game:GetService("StarterGui"):SetCore("SendNotification", {
            Title = "Success!",
            Text = "Auto Farm enabled.",
            Duration = 5,
        })
        spawn(AutoFarmLoop)
    else
        game:GetService("StarterGui"):SetCore("SendNotification", {
            Title = "Info!",
            Text = "Auto Farm disabled.",
            Duration = 5,
        })
    end
end)

---- Function Move
local function MoveToPosition(targetPosition)
    local player = game.Players.LocalPlayer
    local character = player.Character
    if not character or not character:FindFirstChild("HumanoidRootPart") then return end

    local rootPart = character.HumanoidRootPart
    local humanoid = character:FindFirstChildOfClass("Humanoid")

    -- Hitung perbedaan posisi
    local direction = (targetPosition - rootPart.Position).unit
    local distance = (targetPosition - rootPart.Position).Magnitude

    -- Jika jarak cukup jauh, gerakkan karakter maju (W)
    if distance > 3 then
        -- Gerakkan maju (W)
        VirtualInputManager:SendKeyEvent(true, Enum.KeyCode.W, false, game)
    else
        -- Jika jarak dekat (sudah di atas sand), hentikan pergerakan
        VirtualInputManager:SendKeyEvent(false, Enum.KeyCode.W, false, game)

        -- Gali atau ambil chest
        local tool = character:FindFirstChildOfClass("Tool") or player.Backpack:FindFirstChildOfClass("Tool")
        if tool then
            tool.RemoteClick:FireServer(targetPosition)
        end
    end
end

---------- [ Auto Farming AI Function ] ----------
local function AutoFarmAILoop()
    while AutoFarmAI do
        local player = game.Players.LocalPlayer
        local character = player.Character
        if not character or not character:FindFirstChild("HumanoidRootPart") then
            wait(1)
            continue
        end

        local rootPart = character.HumanoidRootPart
        local tool = character:FindFirstChildOfClass("Tool") or player.Backpack:FindFirstChildOfClass("Tool")

        if not tool then
            game:GetService("StarterGui"):SetCore("SendNotification", {
                Title = "Error!",
                Text = "No tool found! Auto Farm AI disabled.",
                Duration = 5,
            })
            AutoFarmAI = false
            return
        end

        -- Cari pasir atau chest terdekat
        local nearestSand, nearestChest
        local shortestDistance = math.huge

        for _, block in pairs(game.Workspace.SandBlocks:GetChildren()) do
            if not block:IsA("BasePart") then continue end

            local distance = (block.Position - rootPart.Position).Magnitude
            if distance < shortestDistance then
                nearestSand = block
                shortestDistance = distance
            end

            if block:FindFirstChild("Chest") then
                nearestChest = block
            end
        end

        -- Prioritaskan chest jika ditemukan
        if nearestChest then
            nearestSand = nearestChest
        end

        -- Jika sand atau chest ditemukan, bergerak menuju target
        if nearestSand then
            MoveToPosition(nearestSand.Position)  -- Gunakan MoveToPosition untuk pergerakan
            wait(FarmingSpeed)  -- Tunggu untuk melakukan aksi farming
        end

        -- Cek apakah Backpack penuh dan jual otomatis jika perlu
        if AutoSellEnabled and IsBackpackFull() then
            FarmPaused = true
            Sell()  -- Panggil fungsi Sell jika Backpack penuh
            FarmPaused = false
        end

        wait(0.1)  -- Tunggu sebentar sebelum melanjutkan ke iterasi berikutnya
    end
end

---------- [ Toggle for Auto Farm AI ] ----------
Main_Home:addToggle('Auto Farm With AI', false, function(state)
    AutoFarmAI = state
    if AutoFarmAI then
        -- Memastikan HumanoidRootPart tidak di-anchored
        local character = game.Players.LocalPlayer.Character
        if character then
            local humanoid = character:FindFirstChildOfClass("Humanoid")
            if humanoid then
                humanoid.PlatformStand = false  -- Pastikan PlatformStand di-nonaktifkan
            end
        end

        game:GetService("StarterGui"):SetCore("SendNotification", {
            Title = "Auto Farm AI Enabled",
            Text = "Auto Farm AI is now active.",
            Duration = 5,
        })
        -- Menjalankan loop AI AutoFarm
        task.spawn(AutoFarmAILoop)  -- Pastikan loop dimulai dengan benar
    else
        -- Mengembalikan kontrol manual karakter
        local character = game.Players.LocalPlayer.Character
        if character then
            local humanoid = character:FindFirstChildOfClass("Humanoid")
            if humanoid then
                humanoid.PlatformStand = false  -- Pastikan PlatformStand di-nonaktifkan saat toggle off
            end
        end

        game:GetService("StarterGui"):SetCore("SendNotification", {
            Title = "Auto Farm AI Disabled",
            Text = "Auto Farm AI is now disabled.",
            Duration = 5,
        })
    end
end)

-- Auto Sell Toggle
Main_Home:addToggle('Auto Sell', false, function(state)
    AutoSellEnabled = state
    game:GetService("StarterGui"):SetCore("SendNotification", {
        Title = state and "Enabled!" or "Disabled!",
        Text = "Auto Sell " .. (state and "enabled." or "disabled."),
        Duration = 5,
    })
end)

---------- [ X-Ray ] ----------
-- Fungsi rekursif untuk mengubah transparansi semua objek
local function SetTransparencyRecursive(object)
    -- Cek jika objek adalah BasePart dan belum diubah transparansinya
    if object:IsA("BasePart") and object.Transparency ~= XRayTransparency then
        object.Transparency = XRayTransparency
    end

    -- Periksa anak objek untuk objek-objek lebih dalam
    for _, child in pairs(object:GetChildren()) do
        SetTransparencyRecursive(child)
    end
end

-- Fungsi untuk mengaktifkan X-Ray
local function EnableXRay()
    SetTransparencyRecursive(workspace)
    while XRayEnabled do
        wait(1)
        SetTransparencyRecursive(workspace)
    end
end

-- Fungsi untuk menonaktifkan X-Ray
local function DisableXRay()
    for _, object in pairs(workspace:GetDescendants()) do
        if object:IsA("BasePart") and object.Transparency ~= 0 then
            object.Transparency = 0
        end
    end
end

-- Toggle untuk mengaktifkan dan menonaktifkan X-Ray
Main_Home:addToggle('X-Ray', false, function(state)
    XRayEnabled = state
    if XRayEnabled then
        game:GetService("StarterGui"):SetCore("SendNotification", {
            Title = "X-Ray Enabled",
            Text = "All objects are now visible.",
            Duration = 5,
        })
        spawn(EnableXRay)
    else
        DisableXRay()
        game:GetService("StarterGui"):SetCore("SendNotification", {
            Title = "X-Ray Disabled",
            Text = "Objects are now back to normal.",
            Duration = 5,
        })
    end
end)

---------- [ Misc Tab Section ] ----------
local Misc_Left = Tab.Home:addSection()
local Main_Misc = Misc_Left:addMenu("#Settings")

---------- [ Misc - Farming Speed Textbox ] ----------
Main_Misc:addTextbox('Farming Speed', tostring(FarmingSpeed), function(value)
    local newFarmingSpeed = tonumber(value)
    if newFarmingSpeed and newFarmingSpeed > 0 then
        FarmingSpeed = newFarmingSpeed
        game:GetService("StarterGui"):SetCore("SendNotification", {
            Title = "Farming Speed Updated!",
            Text = "Farming speed set to: " .. tostring(newFarmingSpeed),
            Duration = 5,
        })
    else
        game:GetService("StarterGui"):SetCore("SendNotification", {
            Title = "Invalid Input",
            Text = "Please enter a valid positive number for Farming Speed.",
            Duration = 5,
        })
    end
end)

---------- [ ESP Tab Section ] ----------
local ESP_Left = Tab.ESP:addSection()
local Main_ESP = ESP_Left:addMenu("#ESP")

---------- [ Misc - ESP Player Toggle ] ----------
-- Fungsi untuk menambahkan highlight pada player
local function AddPlayerESP(player)
    if player.Character and player.Character:FindFirstChild("HumanoidRootPart") then
        local highlight = Instance.new("Highlight")
        highlight.Parent = player.Character
        highlight.Adornee = player.Character.HumanoidRootPart
        highlight.FillColor = Color3.fromRGB(255, 0, 0)  -- Highlight berwarna merah
        highlight.FillTransparency = 0.5
        highlight.OutlineColor = Color3.fromRGB(255, 255, 255)  -- Outline berwarna putih
        highlight.OutlineTransparency = 0.5

        -- Menambahkan nama player di atas highlight
        local nameLabel = Instance.new("BillboardGui")
        nameLabel.Parent = player.Character
        nameLabel.Adornee = player.Character.HumanoidRootPart
        nameLabel.Size = UDim2.new(0, 100, 0, 50)
        nameLabel.StudsOffset = Vector3.new(0, 3, 0)
        nameLabel.AlwaysOnTop = true

        local textLabel = Instance.new("TextLabel")
        textLabel.Parent = nameLabel
        textLabel.Size = UDim2.new(1, 0, 1, 0)
        textLabel.Text = player.Name
        textLabel.TextColor3 = Color3.fromRGB(255, 255, 255)
        textLabel.BackgroundTransparency = 1
        textLabel.TextStrokeTransparency = 0.5

        -- Menambahkan jarak di atas nama player
        local distanceLabel = Instance.new("TextLabel")
        distanceLabel.Parent = nameLabel
        distanceLabel.Size = UDim2.new(1, 0, 1, 20)
        distanceLabel.Position = UDim2.new(0, 0, 1, 0)
        distanceLabel.TextColor3 = Color3.fromRGB(255, 255, 255)
        distanceLabel.BackgroundTransparency = 1
        distanceLabel.TextStrokeTransparency = 0.5

        -- Update jarak setiap detik
        spawn(function()
            while ESPPlayerEnabled do
                local distance = (player.Character.HumanoidRootPart.Position - game.Players.LocalPlayer.Character.HumanoidRootPart.Position).Magnitude
                distanceLabel.Text = string.format("Distance: %.2f", distance)
                wait(1)
            end
        end)

        -- Simpan highlight dan label player dalam tabel
        table.insert(PlayerHighlights, {player = player, highlight = highlight, nameLabel = nameLabel})
    end
end

-- Fungsi untuk menghapus ESP player
local function RemovePlayerESP(player)
    for _, esp in pairs(PlayerHighlights) do
        if esp.player == player then
            esp.highlight:Destroy()
            esp.nameLabel:Destroy()
            table.remove(PlayerHighlights, _)
            break
        end
    end
end

-- Fungsi untuk mengaktifkan ESP Player
local function EnableESPPlayer()
    for _, player in pairs(game.Players:GetPlayers()) do
        if player ~= game.Players.LocalPlayer then
            AddPlayerESP(player)
        end
    end

    -- Tambahkan ESP ketika pemain baru bergabung
    game.Players.PlayerAdded:Connect(function(player)
        if player ~= game.Players.LocalPlayer then
            AddPlayerESP(player)
        end
    end)

    -- Hapus ESP ketika pemain meninggalkan permainan
    game.Players.PlayerRemoving:Connect(function(player)
        RemovePlayerESP(player)
    end)
end

-- Fungsi untuk menonaktifkan ESP Player
local function DisableESPPlayer()
    for _, esp in pairs(PlayerHighlights) do
        esp.highlight:Destroy()
        esp.nameLabel:Destroy()
    end
    PlayerHighlights = {}
end

-- Toggle untuk mengaktifkan dan menonaktifkan ESP Player
Main_ESP:addToggle('ESP Player', false, function(state)
    ESPPlayerEnabled = state
    if ESPPlayerEnabled then
        game:GetService("StarterGui"):SetCore("SendNotification", {
            Title = "ESP Player Enabled",
            Text = "Player highlights and distances are now visible.",
            Duration = 5,
        })
        EnableESPPlayer()
    else
        game:GetService("StarterGui"):SetCore("SendNotification", {
            Title = "ESP Player Disabled",
            Text = "Player highlights and distances are now hidden.",
            Duration = 5,
        })
        DisableESPPlayer()
    end
end)

---------- [ Misc - ESP Chest Toggle ] ----------
Main_ESP:addToggle('ESP Chest', false, function(state)
    ESPEnabled = state

    if state then
        for _, v in pairs(game.Workspace.SandBlocks:GetChildren()) do
            if v:FindFirstChild("Chest") then
                local highlight = Instance.new("Highlight")
                highlight.Parent = v
                highlight.Adornee = v
                highlight.FillColor = Color3.fromRGB(255, 0, 0)
                highlight.FillTransparency = 0.5
                highlight.OutlineColor = Color3.fromRGB(255, 255, 255)
                highlight.OutlineTransparency = 0.5
                table.insert(ChestHighlights, highlight)
            end
        end
    else
        for _, highlight in pairs(ChestHighlights) do
            highlight:Destroy()
        end
        ChestHighlights = {}
    end
end)

-- Update ESP
spawn(function()
    while true do
        if ESPEnabled then
            for _, v in pairs(game.Workspace.SandBlocks:GetChildren()) do
                if v:FindFirstChild("Chest") then
                    local highlightExists = false
                    for _, highlight in pairs(ChestHighlights) do
                        if highlight.Adornee == v then
                            highlightExists = true
                            break
                        end
                    end

                    if not highlightExists then
                        local highlight = Instance.new("Highlight")
                        highlight.Parent = v
                        highlight.Adornee = v
                        highlight.FillColor = Color3.fromRGB(255, 0, 0)
                        highlight.FillTransparency = 0.5
                        highlight.OutlineColor = Color3.fromRGB(255, 255, 255)
                        highlight.OutlineTransparency = 0.5
                        table.insert(ChestHighlights, highlight)
                    end
                end
            end

            for i = #ChestHighlights, 1, -1 do
                local highlight = ChestHighlights[i]
                if not highlight.Adornee or not highlight.Adornee.Parent then
                    highlight:Destroy()
                    table.remove(ChestHighlights, i)
                end
            end
        end
        wait(1)
    end
end)

Features & Information

New update feature + X-Ray + ESP player + Auto Farm With Ai (Beta Test) Maybe I need adjustments for the explosive type digger in the auto farm feature.
#free#Open Source#TreasureHuntSimulator

Community Comments (8)

JustShareJustShareJan 30, 2025(edited)

Bruh I'm tired of making auto farms with AI features, it's very troublesome and annoying

JustShareJustShareJan 30, 2025(edited)

and the logic is very complex, starting from validation, searching for sand and chests adding conditions if there is a chest then prioritizing the chest and much more

copiumxcopiumxJan 30, 2025(edited)

pls script for arcane conquest

JustShareJustShareJan 31, 2025(edited)

@copiumx hmm

copiumxcopiumxJan 31, 2025(edited)

πŸ€”πŸ€”πŸ€”πŸ€”πŸ€”

copiumxcopiumxJan 31, 2025(edited)

@JustShareOpenSource if u decide to make it, Im begging u to not make it open source I ain't want patches

JustShareJustShareJan 31, 2025(edited)

@copiumx sorry bro i can't

copiumxcopiumxJan 31, 2025(edited)

@JustShare its all good I'll try my self

More Scripts for Treasure Hunt Simulator