Testing Only
Key RequiredUniversal

Testing Only

Universal Scriptrakahangtuah620rakahangtuah620 524 views 40 executesUpdated Apr 13, 2026
Unrated
00
Lua Script•280 lines (10758 chars)
--[[
	WARNING: Heads up! This script has not been verified by ScriptBlox. Use at your own risk!
]]
--[[
	MODIFIED: Listener Target Locked + Glide Return (FIXED v2)
]]
if not game:IsLoaded() then game.Loaded:Wait() end
local Players = game:GetService("Players")
local LP = Players.LocalPlayer
repeat task.wait(0.1) until LP.Character and LP.Character:FindFirstChild("HumanoidRootPart")

local EMERALD_ID = "rbxassetid://12796568017"
local MAX_SCAN_RANGE = 3500 

local SETTINGS = {
    GLIDE_SPEED = 300,
    MINE_DISTANCE = 14,
    STOP_DISTANCE = 5,
    STUCK_TIMEOUT = 10,
    GLIDE_TIMEOUT_BUFFER = 3,        -- extra seconds before force-canceling glide
    MINE_SWITCH_COOLDOWN = 0.3        -- delay sebelum mulai mine target baru
}

local RunService = game:GetService("RunService")
local TweenService = game:GetService("TweenService")
local VirtualInputManager = game:GetService("VirtualInputManager")
local Camera = workspace.CurrentCamera

local trackedEmeralds = {}
local ignoredEmeralds = {}
local totalInFrame = 0 
local closestEmerald = nil
local currentTarget = nil 
local isTeleporting = false
local isGliding = false              -- flag khusus: sedang dalam 1 sesi glide
local isMining = false
local lastMineTime = tick()
local lastTargetSwitchTime = 0       -- waktu terakhir target berubah

local savedPosition = nil
local isReturning = false
local activeGlideTween = nil         -- track tween aktif

local function cleanupGlide(char)
    isTeleporting = false
    isGliding = false
    if char then
        for _, p in pairs(char:GetDescendants()) do 
            if p:IsA("BasePart") then p.CanCollide = true end 
        end
    end
    -- hapus semua BodyVelocity sisa
    if char then
        local root = char:FindFirstChild("HumanoidRootPart")
        if root then
            for _, bv in pairs(root:GetChildren()) do
                if bv:IsA("BodyVelocity") then bv:Destroy() end
            end
        end
    end
end

local function performGlide(targetPos, isReturningToSave)
    -- Jangan mulai glide baru jika sedang glide atau glide return aktif berlawanan arah
    if isTeleporting or isGliding then return end
    -- Jika sedang return ke home, jangan izinkan glide ke emerald
    if isReturning and not isReturningToSave then return end

    local char = LP.Character
    local root = char and char:FindFirstChild("HumanoidRootPart")
    if not root then return end

    -- Jarak terlalu kecil? Skip agar tidak glide bolak-balik
    local d = (targetPos - root.Position).Magnitude
    if d < 2 then return end

    isTeleporting = true
    isGliding = true
    for _, p in pairs(char:GetDescendants()) do if p:IsA("BasePart") then p.CanCollide = false end end

    local bv = Instance.new("BodyVelocity", root)
    bv.MaxForce = Vector3.new(math.huge, math.huge, math.huge)
    bv.Velocity = Vector3.new(0,0,0)

    local duration = d / SETTINGS.GLIDE_SPEED
    if duration < 0.05 then duration = 0.05 end

    -- Arah look: dari posisi sekarang menuju target (bukan terbalik)
    local tCFrame = CFrame.new(targetPos, root.Position + (targetPos - root.Position).Unit)

    -- cancel tween lama jika ada
    if activeGlideTween then
        activeGlideTween:Cancel()
        activeGlideTween = nil
    end

    local t = TweenService:Create(root, TweenInfo.new(duration, Enum.EasingStyle.Linear), {CFrame = tCFrame})
    activeGlideTween = t
    t:Play()

    -- TIMEOUT FALLBACK: jika tween tidak selesai dalam waktu yang diharapkan
    task.delay(duration + SETTINGS.GLIDE_TIMEOUT_BUFFER, function()
        if isGliding and activeGlideTween == t then
            warn("[AutoFarm] Glide timeout — force reset")
            t:Cancel()
            bv:Destroy()
            cleanupGlide(char)
            activeGlideTween = nil
            if isReturningToSave then
                savedPosition = nil
                isReturning = false
            end
        end
    end)

    t.Completed:Connect(function()
        bv:Destroy()
        cleanupGlide(char)
        activeGlideTween = nil

        -- Reset orientasi agar karakter tidak miring setelah glide
        local hrp = char and char:FindFirstChild("HumanoidRootPart")
        if hrp then
            hrp.CFrame = CFrame.new(hrp.Position)  -- upright, no tilt
        end
        -- Reset Humanoid state agar tidak ngadet
        local hum = char and char:FindFirstChildOfClass("Humanoid")
        if hum then
            hum:ChangeState(Enum.HumanoidStateType.GettingUp)
        end

        if isReturningToSave then
            savedPosition = nil
            isReturning = false
        end
    end)
end

local function stopMining()
    if isMining then
        isMining = false
        VirtualInputManager:SendMouseButtonEvent(0, 0, 0, false, game, 1)
    end
end

local function forceApplyESP(part)
    if not part:IsA("BasePart") or trackedEmeralds[part] then return end
    local mId = ""
    if part:IsA("MeshPart") then mId = part.MeshId
    else
        local m = part:FindFirstChildOfClass("SpecialMesh")
        if m then mId = m.MeshId end
    end
    
    if mId == EMERALD_ID or part.Name:lower():find("emerald") then
        trackedEmeralds[part] = part
        part.AncestryChanged:Connect(function()
            if not part:IsDescendantOf(workspace) then
                trackedEmeralds[part] = nil
                -- HANYA reset mining jika part ini yang sedang di-mine
                if currentTarget == part then
                    stopMining()
                    currentTarget = nil
                    lastTargetSwitchTime = tick()  -- trigger cooldown
                end
            end
        end)
    end
end

task.spawn(function()
    for _, v in ipairs(workspace:GetDescendants()) do forceApplyESP(v) end
    workspace.DescendantAdded:Connect(forceApplyESP)
    
    while true do
        task.wait(1)
        if isMining and tick() - lastMineTime > SETTINGS.STUCK_TIMEOUT then
            warn("[AutoFarm] Mining stuck timeout — skipping target")
            if currentTarget then ignoredEmeralds[currentTarget] = true end
            currentTarget = nil
            stopMining()
        end
    end
end)

local sg = Instance.new("ScreenGui", LP.PlayerGui)
local f = Instance.new("Frame", sg); f.Size = UDim2.new(0, 260, 0, 85); f.Position = UDim2.new(0.5, -130, 0.85, 0); f.BackgroundColor3 = Color3.new(0,0,0); f.BackgroundTransparency = 0.4; Instance.new("UICorner", f)
local t1 = Instance.new("TextLabel", f); t1.Size = UDim2.new(1, 0, 0.4, 0); t1.BackgroundTransparency = 1; t1.Font = Enum.Font.GothamBold; t1.TextColor3 = Color3.new(1,1,1); t1.TextSize = 14
local t2 = Instance.new("TextLabel", f); t2.Size = UDim2.new(1, 0, 0.3, 0); t2.Position = UDim2.new(0,0,0.4,0); t2.BackgroundTransparency = 1; t2.Font = Enum.Font.Code; t2.TextSize = 12; t2.TextColor3 = Color3.new(1,1,1)
local t3 = Instance.new("TextLabel", f); t3.Size = UDim2.new(1, 0, 0.3, 0); t3.Position = UDim2.new(0,0,0.7,0); t3.BackgroundTransparency = 1; t3.Font = Enum.Font.Gotham; t3.TextSize = 10; t3.TextColor3 = Color3.new(0.7,0.7,0.7)

RunService.RenderStepped:Connect(function()
    local root = LP.Character and LP.Character:FindFirstChild("HumanoidRootPart")
    if not root then return end
    
    local distTable = {}
    totalInFrame = 0
    local isCurrentTargetValid = false
    
    for p, _ in pairs(trackedEmeralds) do 
        if p and p.Parent and not ignoredEmeralds[p] then 
            local d = (p.Position - root.Position).Magnitude
            if d <= MAX_SCAN_RANGE then
                totalInFrame = totalInFrame + 1
                table.insert(distTable, {p = p, d = d})
                if p == currentTarget then
                    isCurrentTargetValid = true
                end
            end
        end 
    end
    
    if isCurrentTargetValid then
        closestEmerald = currentTarget 
    else
        table.sort(distTable, function(a, b) return a.d < b.d end)
        local newTarget = distTable[1] and distTable[1].p or nil
        if newTarget ~= currentTarget then
            currentTarget = newTarget
            lastTargetSwitchTime = tick()  -- catat waktu switch
            stopMining()                   -- PASTI release mouse dulu sebelum switch
        end
        closestEmerald = currentTarget
    end
    
    if totalInFrame > 0 and closestEmerald then
        -- Simpan posisi awal HANYA jika benar-benar idle (tidak gliding, tidak returning)
        if not savedPosition and not isReturning and not isGliding and not isTeleporting then
            savedPosition = root.Position
        end
        
        t1.Text = "💎 TARGETS: " .. totalInFrame
        local d = (closestEmerald.Position - root.Position).Magnitude
        
        if d < SETTINGS.MINE_DISTANCE then
            -- COOLDOWN: tunggu sebentar setelah target switch sebelum mulai mine
            if tick() - lastTargetSwitchTime < SETTINGS.MINE_SWITCH_COOLDOWN then
                t2.Text = "STATUS: SWITCHING..."
                return
            end
            
            local screenPos, onScreen = Camera:WorldToViewportPoint(closestEmerald.Position)
            root.CFrame = CFrame.new(root.Position, Vector3.new(closestEmerald.Position.X, root.Position.Y, closestEmerald.Position.Z))
            Camera.CFrame = CFrame.new(Camera.CFrame.Position, closestEmerald.Position)
            
            if not isMining then
                isMining = true
                lastMineTime = tick()
                VirtualInputManager:SendMouseMoveEvent(screenPos.X, screenPos.Y, game)
                VirtualInputManager:SendMouseButtonEvent(screenPos.X, screenPos.Y, 0, true, game, 1)
            end
            t2.Text = "STATUS: MINING..."
        else
            stopMining()
            t2.Text = "STATUS: GLIDING..."
            -- Hanya glide jika tidak sedang aktif glide dan tidak sedang balik ke home
            if not isTeleporting and not isGliding and not isReturning then
                local direction = (root.Position - closestEmerald.Position).Unit
                local destPos = closestEmerald.Position + (direction * SETTINGS.STOP_DISTANCE)
                performGlide(destPos, false)
            end
        end
    else
        stopMining()  -- pastikan mining berhenti jika tidak ada target
        
        if savedPosition then
            isReturning = true
            t1.Text = "🛰️ GLIDING HOME"
            t2.Text = "STATUS: GLIDING BACK..."
            
            if not isTeleporting then
                local returnPos = savedPosition + Vector3.new(0, 1, 0)  -- offset Y agar tidak stuck ke block
                performGlide(returnPos, true)
            end
        else
            t1.Text = "🛰️ AREA CLEARED"
            t2.Text = "STATUS: STANDBY..."
        end
    end
end)

Features & Information

just for testing

Community Comments (0)

No comments yet for this script.

More Scripts for Universal Scripts