local Players = game:GetService("Players") local UserInputService = game:GetService("UserInputService") local player = Players.LocalPlayer local character = player.Character or player.CharacterAdded:Wait() local hrp = character:WaitForChild("HumanoidRootPart") local StarterGui = game:GetService("StarterGui") -- Paths local BarrelsFolder = workspace.Barrels.Barrels -- Settings local HIGH_ALTITUDE = 500 local HORIZ_STEP = 50 local HORIZ_DELAY = 0.02 local VERT_STEP = 2 local VERT_DELAY = 0.01 local CLICK_OFFSET = 2 local CLICK_RETRIES = 3 local COOLDOWN = 15 local TARGET_TIMEOUT = 5 -- max seconds per target local barrelCooldowns = {} local autoFarmEnabled = true -- starts on -- PC toggle: press F UserInputService.InputBegan:Connect(function(input, gameProcessed) if gameProcessed then return end if input.UserInputType == Enum.UserInputType.Keyboard then if input.KeyCode == Enum.KeyCode.F then autoFarmEnabled = not autoFarmEnabled print("Auto-farm toggled:", autoFarmEnabled) end end end) -- Mobile / GUI toggle button local screenGui = Instance.new("ScreenGui") screenGui.Name = "AutoFarmToggleGui" screenGui.ResetOnSpawn = false screenGui.Parent = player:WaitForChild("PlayerGui") local button = Instance.new("TextButton") button.Size = UDim2.new(0, 150, 0, 50) button.Position = UDim2.new(0, 20, 0, 20) button.BackgroundColor3 = Color3.fromRGB(50, 50, 50) button.TextColor3 = Color3.fromRGB(255, 255, 255) button.Text = autoFarmEnabled and "AutoFarm: ON" or "AutoFarm: OFF" button.Parent = screenGui button.MouseButton1Click:Connect(function() autoFarmEnabled = not autoFarmEnabled button.Text = autoFarmEnabled and "AutoFarm: ON" or "AutoFarm: OFF" end) -- Move horizontally high above map local function moveHighTo(targetPos) local startPos = hrp.Position local startHigh = Vector3.new(startPos.X, HIGH_ALTITUDE, startPos.Z) local targetHigh = Vector3.new(targetPos.X, HIGH_ALTITUDE, targetPos.Z) local direction = (targetHigh - startHigh).Unit local distance = (targetHigh - startHigh).Magnitude local steps = math.floor(distance / HORIZ_STEP) for i = 1, steps do if not autoFarmEnabled then return false end local stepPos = startHigh + direction * (i * HORIZ_STEP) hrp.CFrame = CFrame.new(stepPos) wait(HORIZ_DELAY) end if autoFarmEnabled then hrp.CFrame = CFrame.new(targetHigh) return true else return false end end -- Descend slowly above target local function descendToTarget(targetPos) local targetY = targetPos.Y + CLICK_OFFSET local startTime = tick() while hrp.Position.Y > targetY do if not autoFarmEnabled then return false end if tick() - startTime > TARGET_TIMEOUT then return false end hrp.CFrame = CFrame.new(hrp.Position.X, math.max(hrp.Position.Y - VERT_STEP, targetY), hrp.Position.Z) wait(VERT_DELAY) end return true end -- Click target safely with retries local function clickTarget(target) if not target or not target:IsA("BasePart") then return end local lastClick = barrelCooldowns[target] or 0 if tick() - lastClick < COOLDOWN then return end local targetPos = target.Position -- Move high if not moveHighTo(targetPos) then return end -- Descend if not descendToTarget(targetPos) then return end -- Attempt clicks local clickDetector = target:FindFirstChildOfClass("ClickDetector") if clickDetector then for i = 1, CLICK_RETRIES do if not autoFarmEnabled then return end fireclickdetector(clickDetector, 0) wait(0.05) end barrelCooldowns[target] = tick() end end -- Auto-farm function in a coroutine local function autoFarm() while true do if autoFarmEnabled then -- Barrels only for _, barrel in ipairs(BarrelsFolder:GetChildren()) do if not autoFarmEnabled then break end clickTarget(barrel) end end wait(0.1) end end -- Start auto-farm coroutine.wrap(autoFarm)()