local Ip = game.Players.LocalPlayer

local function getPlayerLevel()
    return Ip.Data.Level.Value
end

local function checkEnemy()
    local level = getPlayerLevel()
    local enemyName
    
    if level < 10 then
        enemyName = "Bandit"
    elseif level >= 10 and level < 40 then
        enemyName = "Monkey"
    end
    return enemyName
end

local function getNPC()
    local dist, thing = math.huge
    for _, v in pairs(game:GetService("Workspace").Enemies:GetChildren()) do
        local enemyName = checkEnemy()
        if enemyName then
            if v.Name == enemyName and v:FindFirstChild("Humanoid") and v.Humanoid.Health > 0 then
                local mag = (Ip.Character.HumanoidRootPart.Position - v.HumanoidRootPart.Position).Magnitude
                if mag < dist then 
                    dist = mag 
                    thing = v 
                end
            end
        end
    end
    return thing
end

local tweens = game:GetService("TweenService")
local humanoidRootPart = Ip.Character.HumanoidRootPart

local function noclip()
    for _, v in pairs(Ip.Character:GetDescendants()) do
        if v:IsA("BasePart") and v.CanCollide == true then
            v.CanCollide = false
        end
    end
end

local function unnoclip()
    for _, v in pairs(Ip.Character:GetDescendants()) do
        if v:IsA("BasePart") and v.CanCollide == false then
            v.CanCollide = true
        end
    end
end

local function antiFall()
    if not antifall then
        antifall = Instance.new("BodyVelocity", HumanoidRootPart)
        antifall.Velocity = Vector3.new(0, 0, 0)
    end
end

local function tweenFarm(v, speed)
    if humanoidRootPart then
        noclip()
        antiFall()
        
        local squarePoints = {
            v + Vector3.new(-10, 30, -10),
            v + Vector3.new(10, 30, -10),
            v + Vector3.new(10, 30, 10),
            v + Vector3.new(-10, 30, 10),
            v + Vector3.new(-10, 30, -10) -- Returning to the first point
        }

        for _, point in ipairs(squarePoints) do
            local cf = CFrame.new(point)
            local distance = (humanoidRootPart.Position - point).Magnitude
            local time = distance / speed
            local tweeninfo = TweenInfo.new(time, Enum.EasingStyle.Linear, Enum.EasingDirection.Out)
            local start_tween = tweens:Create(humanoidRootPart, tweeninfo, {CFrame = cf})

            start_tween:Play()
            start_tween.Completed:Wait()
        end
        
        unnoclip()
    end
end

getgenv().farm = true
while getgenv().farm do
    task.wait()
    pcall(function()
        local npc = getNPC()
        if npc then
            tweenFarm(npc.HumanoidRootPart.Position + Vector3.new(0, 20, 0), 150)
            game:GetService("VirtualUser"):ClickButton1(Vector2.new(9e9, 9e9))
        end
    end)
end

Embed on website

To embed this project on your website, copy the following code and paste it into your website's HTML: