lookat gui
Key RequiredUniversal

lookat gui

Universal Scriptalfountain18alfountain18 989 views 69 executesUpdated Oct 17, 2025
5.0/ 5(1 votes)
10100% Positive
Lua Script•1187 lines (51077 chars)
-- LocalScript (StarterGui)
-- PlayerMover v11 — separate LookAt and LookAtV2 prediction setters (per-target + universal)
-- Replaces earlier script; keeps Universal page + mix modes + CFrame walk + BV fly + Above + anti-stuck
-- Paste into StarterGui

local Players = game:GetService("Players")
local RunService = game:GetService("RunService")
local TweenService = game:GetService("TweenService")

local LocalPlayer = Players.LocalPlayer
local Workspace = workspace

-- ===== Defaults =====
local DEFAULT_CFRAME_WALK_SPEED = 1    -- studs per frame
local DEFAULT_BV_SPEED = 6             -- studs/sec (BV fly)
local DEFAULT_PRED = 0.12              -- seconds for prediction (walk/fly/shared)
local DEFAULT_LOOK_PRED = 0.12         -- LookAt (XY) prediction default
local DEFAULT_LOOKV2_PRED = 0.12       -- LookAtV2 (XYZ+roll) prediction default
local DEFAULT_ABOVE_TWEEN = 0.05

local STUCK_TIME_THRESHOLD = 1.2
local STUCK_MOVE_EPS = 0.12
local COLLIDE_MIN_DIST = 0.75

-- ===== State flags =====
local selectedPlayer = nil

local cframeWalkActive = false
local universalForwardActive = false
local universalWalkToPlayersActive = false
local flyActive = false
local universalAutoFly = false

local aboveActive = false
local lookActive = false      -- per-target LookAt (XY)
local lookV2Active = false    -- per-target LookAtV2 (XYZ+roll)

-- Universal look flags
local universalLook = false
local universalLookV2 = false

-- Universal combat/mix modes and offsets
local uniCFrameMode = "Normal"
local uniFlyMode = "Normal"
local uniOffset = 2
local uniMixWalkMode = "Normal"
local uniMixFlyMode = "Normal"

-- BV controllers
local bv, bg, ctrlRootPart = nil, nil, nil

-- prediction state per player
local playerState = {} -- player -> {pos, vel, t}

-- anti-stuck
local lastMyPos = nil
local lastMovedAt = tick()

-- ===== Helpers =====
local function clamp(n, a, b)
    if n < a then return a end
    if n > b then return b end
    return n
end

local function safeChar(plr)
    return (plr and plr.Character) and plr.Character or nil
end

local function bestPart(plr)
    local ch = safeChar(plr)
    if not ch then return nil end
    return ch:FindFirstChild("HumanoidRootPart") or ch:FindFirstChild("UpperTorso")
           or ch:FindFirstChild("Torso") or ch:FindFirstChild("Head")
end

local function isAlive(plr)
    local ch = safeChar(plr)
    if not ch then return false end
    local hum = ch:FindFirstChildOfClass("Humanoid")
    return hum and hum.Health and hum.Health > 0
end

-- update prediction states each frame
local function updatePlayerState(plr, now)
    local part = bestPart(plr)
    if not playerState[plr] then playerState[plr] = {pos = nil, vel = Vector3.new(0,0,0), t = now} end
    local st = playerState[plr]
    if not part then
        st.pos = nil; st.vel = Vector3.new(0,0,0); st.t = now
        return
    end
    local cur = part.Position
    if st.pos and st.t then
        local dt = math.max(1e-4, now - st.t)
        st.vel = (cur - st.pos) / dt
    else
        st.vel = Vector3.new(0,0,0)
    end
    st.pos = cur
    st.t = now
end

local function predictedPosition(plr, predSecs)
    local part = bestPart(plr)
    if not part then return nil end
    local st = playerState[plr]
    if st and st.pos and st.vel and predSecs and predSecs > 0 then
        return part.Position + st.vel * predSecs
    end
    return part.Position
end

local function isPositionCollidingWithPlayers(pos)
    if not pos then return false end
    for _,p in ipairs(Players:GetPlayers()) do
        if p ~= LocalPlayer then
            local pr = bestPart(p)
            if pr and pr.Position and (pos - pr.Position).Magnitude < COLLIDE_MIN_DIST then
                return true
            end
        end
    end
    return false
end

-- BV controllers for fly
local function ensureControllers()
    local char = LocalPlayer.Character
    if not char then return end
    local root = char:FindFirstChild("HumanoidRootPart") or char:FindFirstChild("UpperTorso") or char:FindFirstChild("Torso")
    if not root then return end
    ctrlRootPart = root
    if not bg or not bg.Parent then
        bg = Instance.new("BodyGyro")
        bg.Name = "PMv11_BodyGyro"
        bg.P = 9e4
        bg.D = 500
        bg.MaxTorque = Vector3.new(9e9,9e9,9e9)
        bg.CFrame = root.CFrame
        bg.Parent = root
    end
    if not bv or not bv.Parent then
        bv = Instance.new("BodyVelocity")
        bv.Name = "PMv11_BodyVelocity"
        bv.MaxForce = Vector3.new(9e9,9e9,9e9)
        bv.Velocity = Vector3.new(0,0,0)
        bv.Parent = root
    end
end

local function removeControllers()
    if bv then pcall(function() bv:Destroy() end) end
    if bg then pcall(function() bg:Destroy() end) end
    bv, bg, ctrlRootPart = nil, nil, nil
end

-- compute desired target position according to mode + offset
-- forFly: if true, include 3D offset; otherwise only horizontal (XZ) offset and keep Y at your HRP Y
-- predSecs: used to predict target movement
local function computeOffsetTarget(plr, mode, offset, forFly, predSecs)
    if not plr then return nil end
    local tgtPart = bestPart(plr)
    if not tgtPart then return nil end
    predSecs = predSecs or (tonumber(walkPredBox and walkPredBox.Text or tostring(DEFAULT_PRED)) or DEFAULT_PRED)
    local basePos = predictedPosition(plr, predSecs) or tgtPart.Position
    local look = nil
    local ok, tgtCFrame = pcall(function() return (tgtPart.CFrame) end)
    if ok and tgtCFrame then look = tgtCFrame.LookVector else look = Vector3.new(0,0,1) end

    offset = tonumber(offset or 0) or 0
    if mode == "Normal" or offset <= 0 then
        if forFly then
            return basePos
        else
            local hrp = LocalPlayer.Character and (LocalPlayer.Character:FindFirstChild("HumanoidRootPart") or LocalPlayer.Character:FindFirstChild("UpperTorso") or LocalPlayer.Character:FindFirstChild("Torso"))
            if hrp then
                return Vector3.new(basePos.X, hrp.Position.Y, basePos.Z)
            else
                return basePos
            end
        end
    end

    local dir = Vector3.new(look.X, (forFly and look.Y or 0), look.Z)
    if dir.Magnitude < 1e-6 then dir = Vector3.new(0,0,1) end

    local desired
    if mode == "Behind" then
        desired = basePos - dir.Unit * offset
    else -- "Front"
        desired = basePos + dir.Unit * offset
    end

    -- Deadzone perimeter logic on XZ plane
    local toDesiredXZ = Vector3.new(desired.X - basePos.X, 0, desired.Z - basePos.Z)
    local distXZ = toDesiredXZ.Magnitude
    if distXZ < offset - 1e-4 then
        local fromMe = LocalPlayer.Character and (LocalPlayer.Character:FindFirstChild("HumanoidRootPart") or LocalPlayer.Character:FindFirstChild("UpperTorso") or LocalPlayer.Character:FindFirstChild("Torso"))
        local angleVec
        if fromMe then
            angleVec = Vector3.new(fromMe.Position.X - basePos.X, 0, fromMe.Position.Z - basePos.Z)
            if angleVec.Magnitude < 1e-4 then
                angleVec = Vector3.new(1,0,0)
            end
        else
            angleVec = Vector3.new(desired.X - basePos.X, 0, desired.Z - basePos.Z)
            if angleVec.Magnitude < 1e-4 then angleVec = Vector3.new(1,0,0) end
        end
        local perimeterXZ = basePos + angleVec.Unit * offset
        if forFly then
            desired = Vector3.new(perimeterXZ.X, desired.Y, perimeterXZ.Z)
        else
            local hrp = LocalPlayer.Character and (LocalPlayer.Character:FindFirstChild("HumanoidRootPart") or LocalPlayer.Character:FindFirstChild("UpperTorso") or LocalPlayer.Character:FindFirstChild("Torso"))
            local y = hrp and hrp.Position.Y or basePos.Y
            desired = Vector3.new(perimeterXZ.X, y, perimeterXZ.Z)
        end
    end

    if isPositionCollidingWithPlayers(desired) then
        desired = desired + Vector3.new(0, 1.2, 0)
    end

    return desired
end

-- CFrame step toward targetPos by exact 'stepDist' studs (studs/frame)
local function cframeStepTowardsExact(hrp, targetPos, stepDist)
    if not (hrp and hrp:IsA("BasePart")) or not targetPos then return end
    local from = hrp.Position
    local dir = targetPos - from
    local dist = dir.Magnitude
    if dist <= 0.001 then return end
    local step = tonumber(stepDist) or DEFAULT_CFRAME_WALK_SPEED
    if step <= 0 then return end

    local t = math.min(1, step / dist)
    local newPos = from:Lerp(targetPos, t)

    if (targetPos - newPos).Magnitude < 0.6 then
        local offset = from - targetPos
        if offset.Magnitude < 0.0001 then offset = Vector3.new(1,0,0) end
        offset = offset.Unit
        newPos = targetPos + offset * 1.1
    end

    if isPositionCollidingWithPlayers(newPos) then
        local nearest, nd = nil, math.huge
        for _,p in ipairs(Players:GetPlayers()) do
            if p ~= LocalPlayer then
                local pr = bestPart(p)
                if pr then
                    local d = (newPos - pr.Position).Magnitude
                    if d < nd then nd = d; nearest = pr end
                end
            end
        end
        if nearest then
            local away = newPos - nearest.Position
            if away.Magnitude < 0.001 then away = Vector3.new(1,0,0) end
            newPos = nearest.Position + away.Unit * (COLLIDE_MIN_DIST + 0.4)
        end
    end

    local look = hrp.CFrame.LookVector
    local newCf = CFrame.new(newPos, newPos + look)
    pcall(function() hrp.CFrame = newCf end)
end

-- CFrame move forward horizontally by stepDist studs (studs/frame) using HRP facing
local function cframeMoveForwardHorizontalExact_ByHRP(hrp, stepDist)
    if not (hrp and hrp:IsA("BasePart")) then return end
    local from = hrp.Position
    local horiz = Vector3.new(hrp.CFrame.LookVector.X, 0, hrp.CFrame.LookVector.Z)
    if horiz.Magnitude < 1e-6 then return end
    local step = tonumber(stepDist) or DEFAULT_CFRAME_WALK_SPEED
    if step <= 0 then return end
    local newPos = from + horiz.Unit * step

    if isPositionCollidingWithPlayers(newPos) then
        newPos = newPos + Vector3.new(0, 1.2, 0)
    end

    local newCf = CFrame.new(newPos, newPos + horiz.Unit)
    pcall(function() hrp.CFrame = newCf end)
end

-- BV fly toward dest using speed (studs/sec) — uses prediction externally
local function flyTowardPositionBV(destPos, speed)
    if not destPos then return end
    ensureControllers()
    if not ctrlRootPart or not bg or not bv then return end
    local myPos = ctrlRootPart.Position
    local to = destPos - myPos
    local dist = to.Magnitude
    if dist < 0.2 then
        bv.Velocity = Vector3.new(0,0,0)
    else
        local dir = to.Unit
        local v = dir * (tonumber(speed) or DEFAULT_BV_SPEED)
        bv.Velocity = v
    end
    bg.CFrame = CFrame.new(ctrlRootPart.Position, destPos)
end

-- LookAt helpers (operate from a position so we can pass offset target)
local function doLookAtPositionXY(pos)
    if not pos then return end
    local ch = LocalPlayer.Character
    local hrp = ch and (ch:FindFirstChild("HumanoidRootPart") or ch:FindFirstChild("UpperTorso") or ch:FindFirstChild("Torso"))
    if not hrp then return end
    local myPos = hrp.Position
    local targetPos = Vector3.new(pos.X, myPos.Y, pos.Z)
    pcall(function() hrp.CFrame = CFrame.new(myPos, targetPos) end)
end

local function doLookAtPositionV2(pos, rollDeg)
    if not pos then return end
    local ch = LocalPlayer.Character
    local hrp = ch and (ch:FindFirstChild("HumanoidRootPart") or ch:FindFirstChild("UpperTorso") or ch:FindFirstChild("Torso"))
    if not hrp then return end
    local base = CFrame.new(hrp.Position, pos)
    local roll = CFrame.Angles(0, 0, math.rad(tonumber(rollDeg) or 0))
    pcall(function() hrp.CFrame = base * roll end)
end

local function getNearestAlivePlayerToMe()
    local myChar = LocalPlayer.Character
    local myRoot = myChar and (myChar:FindFirstChild("HumanoidRootPart") or myChar:FindFirstChild("UpperTorso") or myChar:FindFirstChild("Torso"))
    if not myRoot then return nil end
    local best, bestDist = nil, math.huge
    for _,p in ipairs(Players:GetPlayers()) do
        if p ~= LocalPlayer and isAlive(p) then
            local pr = bestPart(p)
            if pr then
                local d = (pr.Position - myRoot.Position).Magnitude
                if d < bestDist then bestDist = d; best = p end
            end
        end
    end
    return best
end

-- ===== UI =====
local screenGui = Instance.new("ScreenGui")
screenGui.Name = "PlayerMoverGui_v11"
screenGui.ResetOnSpawn = false
screenGui.Parent = LocalPlayer:WaitForChild("PlayerGui")

local main = Instance.new("Frame", screenGui)
main.Name = "Main"
main.Size = UDim2.new(0, 700, 0, 580)
main.Position = UDim2.new(0.02, 0, 0.06, 0)
main.BackgroundColor3 = Color3.fromRGB(20,20,22)
main.BorderSizePixel = 0
main.Active = true

local header = Instance.new("Frame", main)
header.Size = UDim2.new(1,0,0,44)
header.BackgroundColor3 = Color3.fromRGB(34,34,36)

local title = Instance.new("TextLabel", header)
title.Position = UDim2.new(0,12,0,6)
title.Size = UDim2.new(0.6,-24,1,-12)
title.BackgroundTransparency = 1
title.Text = "PlayerMover v11 (separate Look preds)"
title.TextColor3 = Color3.fromRGB(240,240,240)
title.Font = Enum.Font.GothamBold
title.TextSize = 18
title.TextXAlignment = Enum.TextXAlignment.Left

local closeBtn = Instance.new("TextButton", header)
closeBtn.Size = UDim2.new(0,40,0,28)
closeBtn.Position = UDim2.new(1, -52, 0.5, -14)
closeBtn.Text = "X"
closeBtn.Font = Enum.Font.Gotham
closeBtn.TextColor3 = Color3.new(1,1,1)
closeBtn.BackgroundColor3 = Color3.fromRGB(160,46,46)
closeBtn.BorderSizePixel = 0

-- tabs
local tabBar = Instance.new("Frame", main)
tabBar.Size = UDim2.new(1,-16,0,36)
tabBar.Position = UDim2.new(0,8,0,52)
tabBar.BackgroundTransparency = 1

local t1 = Instance.new("TextButton", tabBar)
t1.Size = UDim2.new(0.5,-6,1,0)
t1.Position = UDim2.new(0,0,0,0)
t1.Text = "Main"
t1.Font = Enum.Font.Gotham
t1.TextSize = 14
t1.BackgroundColor3 = Color3.fromRGB(60,60,60)

local t2 = Instance.new("TextButton", tabBar)
t2.Size = UDim2.new(0.5,-6,1,0)
t2.Position = UDim2.new(0.5,8,0,0)
t2.Text = "Universal"
t2.Font = Enum.Font.Gotham
t2.TextSize = 14
t2.BackgroundColor3 = Color3.fromRGB(36,36,40)

-- pages
local pageMain = Instance.new("Frame", main)
pageMain.Size = UDim2.new(1,-16,1,-160)
pageMain.Position = UDim2.new(0,8,0,96)
pageMain.BackgroundTransparency = 1

local pageUni = Instance.new("Frame", main)
pageUni.Size = pageMain.Size
pageUni.Position = pageMain.Position
pageUni.BackgroundTransparency = 1
pageUni.Visible = false

-- player list on main
local listFrame = Instance.new("Frame", pageMain)
listFrame.Size = UDim2.new(0.44,0,1,0)
listFrame.BackgroundColor3 = Color3.fromRGB(26,26,28)

local listTitle = Instance.new("TextLabel", listFrame)
listTitle.Size = UDim2.new(1,0,0,28)
listTitle.BackgroundTransparency = 1
listTitle.Font = Enum.Font.GothamBold
listTitle.TextSize = 14
listTitle.TextColor3 = Color3.fromRGB(230,230,230)
listTitle.Text = "Players"

local playerScroll = Instance.new("ScrollingFrame", listFrame)
playerScroll.Position = UDim2.new(0,8,0,36)
playerScroll.Size = UDim2.new(1,-16,1,-44)
playerScroll.BackgroundTransparency = 1
playerScroll.ScrollBarThickness = 6
local listLayout = Instance.new("UIListLayout", playerScroll)
listLayout.Padding = UDim.new(0,6)
listLayout.SortOrder = Enum.SortOrder.LayoutOrder

-- controls main
local ctrl = Instance.new("Frame", pageMain)
ctrl.Size = UDim2.new(0.54,0,1,0)
ctrl.Position = UDim2.new(0.46,8,0,0)
ctrl.BackgroundTransparency = 1

local selLabel = Instance.new("TextLabel", ctrl)
selLabel.Position = UDim2.new(0,8,0,6)
selLabel.Size = UDim2.new(1,-16,0,22)
selLabel.BackgroundTransparency = 1
selLabel.Font = Enum.Font.Gotham
selLabel.TextSize = 14
selLabel.TextColor3 = Color3.fromRGB(220,220,220)
selLabel.Text = "Selected: <none>"

-- shared controls on main
local walkSpeedLbl = Instance.new("TextLabel", ctrl)
walkSpeedLbl.Position = UDim2.new(0,8,0,36)
walkSpeedLbl.Size = UDim2.new(0,260,0,18)
walkSpeedLbl.BackgroundTransparency = 1
walkSpeedLbl.Font = Enum.Font.Gotham
walkSpeedLbl.TextSize = 14
walkSpeedLbl.Text = "CFrame Walk Speed (studs/frame):"

local walkSpeedBox = Instance.new("TextBox", ctrl)
walkSpeedBox.Position = UDim2.new(0,270,0,32)
walkSpeedBox.Size = UDim2.new(0,96,0,26)
walkSpeedBox.Text = tostring(DEFAULT_CFRAME_WALK_SPEED)
walkSpeedBox.ClearTextOnFocus = false
walkSpeedBox.Font = Enum.Font.Gotham

local predLbl = Instance.new("TextLabel", ctrl)
predLbl.Position = UDim2.new(0,8,0,68)
predLbl.Size = UDim2.new(0,200,0,18)
predLbl.BackgroundTransparency = 1
predLbl.Font = Enum.Font.Gotham
predLbl.Text = "Prediction (s) for Walk/Fly (shared):"

local walkPredBox = Instance.new("TextBox", ctrl)
walkPredBox.Position = UDim2.new(0,210,0,64)
walkPredBox.Size = UDim2.new(0,96,0,26)
walkPredBox.Text = tostring(DEFAULT_PRED)
walkPredBox.ClearTextOnFocus = false
walkPredBox.Font = Enum.Font.Gotham

-- DEDICATED look prediction boxes (separate now)
local lookPredLbl = Instance.new("TextLabel", ctrl)
lookPredLbl.Position = UDim2.new(0,8,0,100)
lookPredLbl.Size = UDim2.new(0,240,0,18)
lookPredLbl.BackgroundTransparency = 1
lookPredLbl.Font = Enum.Font.Gotham
lookPredLbl.Text = "LookAt prediction (s) — used by LookAt (XY):"

local lookPredBox = Instance.new("TextBox", ctrl)
lookPredBox.Position = UDim2.new(0,260,0,96)
lookPredBox.Size = UDim2.new(0,96,0,26)
lookPredBox.Text = tostring(DEFAULT_LOOK_PRED)
lookPredBox.ClearTextOnFocus = false
lookPredBox.Font = Enum.Font.Gotham

local lookV2PredLbl = Instance.new("TextLabel", ctrl)
lookV2PredLbl.Position = UDim2.new(0,8,0,132)
lookV2PredLbl.Size = UDim2.new(0,240,0,18)
lookV2PredLbl.BackgroundTransparency = 1
lookV2PredLbl.Font = Enum.Font.Gotham
lookV2PredLbl.Text = "LookAtV2 prediction (s) — used by LookAtV2 (XYZ):"

local lookV2PredBox = Instance.new("TextBox", ctrl)
lookV2PredBox.Position = UDim2.new(0,260,0,128)
lookV2PredBox.Size = UDim2.new(0,96,0,26)
lookV2PredBox.Text = tostring(DEFAULT_LOOKV2_PRED)
lookV2PredBox.ClearTextOnFocus = false
lookV2PredBox.Font = Enum.Font.Gotham

local cwalkBtn = Instance.new("TextButton", ctrl)
cwalkBtn.Position = UDim2.new(0,8,0,168)
cwalkBtn.Size = UDim2.new(0,240,0,36)
cwalkBtn.Text = "CFrame Walk (to selected): OFF"
cwalkBtn.Font = Enum.Font.Gotham
cwalkBtn.BackgroundColor3 = Color3.fromRGB(90,90,90)

local flySpeedLbl = Instance.new("TextLabel", ctrl)
flySpeedLbl.Position = UDim2.new(0,8,0,216)
flySpeedLbl.Size = UDim2.new(0,220,0,18)
flySpeedLbl.BackgroundTransparency = 1
flySpeedLbl.Font = Enum.Font.Gotham
flySpeedLbl.Text = "Fly BV Speed (studs/sec):"

local flySpeedBox = Instance.new("TextBox", ctrl)
flySpeedBox.Position = UDim2.new(0,230,0,212)
flySpeedBox.Size = UDim2.new(0,96,0,26)
flySpeedBox.Text = tostring(DEFAULT_BV_SPEED)
flySpeedBox.ClearTextOnFocus = false
flySpeedBox.Font = Enum.Font.Gotham

local flyPredLbl = Instance.new("TextLabel", ctrl)
flyPredLbl.Position = UDim2.new(0,8,0,252)
flyPredLbl.Size = UDim2.new(0,160,0,18)
flyPredLbl.BackgroundTransparency = 1
flyPredLbl.Font = Enum.Font.Gotham
flyPredLbl.Text = "Fly Prediction (s):"

local flyPredBox = Instance.new("TextBox", ctrl)
flyPredBox.Position = UDim2.new(0,170,0,248)
flyPredBox.Size = UDim2.new(0,96,0,26)
flyPredBox.Text = tostring(DEFAULT_PRED)
flyPredBox.ClearTextOnFocus = false
flyPredBox.Font = Enum.Font.Gotham

local flyBtn = Instance.new("TextButton", ctrl)
flyBtn.Position = UDim2.new(0,8,0,288)
flyBtn.Size = UDim2.new(0,240,0,36)
flyBtn.Text = "Fly (BV to selected): OFF"
flyBtn.Font = Enum.Font.Gotham
flyBtn.BackgroundColor3 = Color3.fromRGB(90,90,90)

-- Above (tween)
local aboveLbl = Instance.new("TextLabel", ctrl)
aboveLbl.Position = UDim2.new(0,8,0,332)
aboveLbl.Size = UDim2.new(0,160,0,18)
aboveLbl.BackgroundTransparency = 1
aboveLbl.Font = Enum.Font.Gotham
aboveLbl.Text = "Above height (studs):"

local aboveBox = Instance.new("TextBox", ctrl)
aboveBox.Position = UDim2.new(0,170,0,328)
aboveBox.Size = UDim2.new(0,96,0,26)
aboveBox.Text = "8"
aboveBox.ClearTextOnFocus = false
aboveBox.Font = Enum.Font.Gotham

local aboveTweenLbl = Instance.new("TextLabel", ctrl)
aboveTweenLbl.Position = UDim2.new(0,8,0,364)
aboveTweenLbl.Size = UDim2.new(0,160,0,18)
aboveTweenLbl.BackgroundTransparency = 1
aboveTweenLbl.Font = Enum.Font.Gotham
aboveTweenLbl.Text = "Above tween time (s):"

local aboveTweenBox = Instance.new("TextBox", ctrl)
aboveTweenBox.Position = UDim2.new(0,170,0,360)
aboveTweenBox.Size = UDim2.new(0,96,0,26)
aboveTweenBox.Text = tostring(DEFAULT_ABOVE_TWEEN)
aboveTweenBox.ClearTextOnFocus = false
aboveTweenBox.Font = Enum.Font.Gotham

local aboveBtn = Instance.new("TextButton", ctrl)
aboveBtn.Position = UDim2.new(0,280,0,328)
aboveBtn.Size = UDim2.new(0,160,0,58)
aboveBtn.Text = "Above: OFF"
aboveBtn.Font = Enum.Font.Gotham
aboveBtn.BackgroundColor3 = Color3.fromRGB(90,90,90)

-- Look toggles (per-target)
local lookBtn = Instance.new("TextButton", ctrl)
lookBtn.Position = UDim2.new(0,8,0,428)
lookBtn.Size = UDim2.new(0,160,0,34)
lookBtn.Text = "LookAt (XY): OFF"
lookBtn.Font = Enum.Font.Gotham

local lookV2Btn = Instance.new("TextButton", ctrl)
lookV2Btn.Position = UDim2.new(0,176,0,428)
lookV2Btn.Size = UDim2.new(0,240,0,34)
lookV2Btn.Text = "LookAtV2 (XYZ+Roll): OFF"
lookV2Btn.Font = Enum.Font.Gotham

-- Universal page controls (including combat mode selectors, offset and mix modes)
local uniTitle = Instance.new("TextLabel", pageUni)
uniTitle.Position = UDim2.new(0,8,0,8)
uniTitle.Size = UDim2.new(1,-16,0,22)
uniTitle.BackgroundTransparency = 1
uniTitle.Font = Enum.Font.GothamBold
uniTitle.Text = "Universal Controls (Combat & Mix Modes)"

local uniForwardBtn = Instance.new("TextButton", pageUni)
uniForwardBtn.Position = UDim2.new(0,8,0,44)
uniForwardBtn.Size = UDim2.new(0,360,0,40)
uniForwardBtn.Text = "Universal Forward CFrame-Walk (HRP facing): OFF"
uniForwardBtn.Font = Enum.Font.Gotham
uniForwardBtn.BackgroundColor3 = Color3.fromRGB(90,90,90)

local uniToPlayersBtn = Instance.new("TextButton", pageUni)
uniToPlayersBtn.Position = UDim2.new(0,8,0,104)
uniToPlayersBtn.Size = UDim2.new(0,360,0,40)
uniToPlayersBtn.Text = "Universal Walk-To-Nearest Player: OFF"
uniToPlayersBtn.Font = Enum.Font.Gotham
uniToPlayersBtn.BackgroundColor3 = Color3.fromRGB(90,90,90)

local uniAutoFlyBtn = Instance.new("TextButton", pageUni)
uniAutoFlyBtn.Position = UDim2.new(0,8,0,164)
uniAutoFlyBtn.Size = UDim2.new(0,360,0,40)
uniAutoFlyBtn.Text = "Universal AutoFly (BV to nearest): OFF"
uniAutoFlyBtn.Font = Enum.Font.Gotham
uniAutoFlyBtn.BackgroundColor3 = Color3.fromRGB(90,90,90)

-- Combat Mode UI (CFrame)
local cframeModeLabel = Instance.new("TextLabel", pageUni)
cframeModeLabel.Position = UDim2.new(0,380,0,48)
cframeModeLabel.Size = UDim2.new(0,260,0,20)
cframeModeLabel.BackgroundTransparency = 1
cframeModeLabel.Font = Enum.Font.GothamBold
cframeModeLabel.Text = "CFrame Mode (walk-to-player):"

local cNormalBtn = Instance.new("TextButton", pageUni)
cNormalBtn.Position = UDim2.new(0,380,0,72)
cNormalBtn.Size = UDim2.new(0,84,0,32)
cNormalBtn.Text = "Normal"
cNormalBtn.Font = Enum.Font.Gotham

local cBehindBtn = Instance.new("TextButton", pageUni)
cBehindBtn.Position = UDim2.new(0,472,0,72)
cBehindBtn.Size = UDim2.new(0,84,0,32)
cBehindBtn.Text = "Behind"
cBehindBtn.Font = Enum.Font.Gotham

local cFrontBtn = Instance.new("TextButton", pageUni)
cFrontBtn.Position = UDim2.new(0,564,0,72)
cFrontBtn.Size = UDim2.new(0,84,0,32)
cFrontBtn.Text = "Front"
cFrontBtn.Font = Enum.Font.Gotham

-- Combat Mode UI (Fly)
local flyModeLabel = Instance.new("TextLabel", pageUni)
flyModeLabel.Position = UDim2.new(0,380,0,116)
flyModeLabel.Size = UDim2.new(0,260,0,20)
flyModeLabel.BackgroundTransparency = 1
flyModeLabel.Font = Enum.Font.GothamBold
flyModeLabel.Text = "Fly Mode (BV to nearest):"

local fNormalBtn = Instance.new("TextButton", pageUni)
fNormalBtn.Position = UDim2.new(0,380,0,140)
fNormalBtn.Size = UDim2.new(0,84,0,32)
fNormalBtn.Text = "Normal"
fNormalBtn.Font = Enum.Font.Gotham

local fBehindBtn = Instance.new("TextButton", pageUni)
fBehindBtn.Position = UDim2.new(0,472,0,140)
fBehindBtn.Size = UDim2.new(0,84,0,32)
fBehindBtn.Text = "Behind"
fBehindBtn.Font = Enum.Font.Gotham

local fFrontBtn = Instance.new("TextButton", pageUni)
fFrontBtn.Position = UDim2.new(0,564,0,140)
fFrontBtn.Size = UDim2.new(0,84,0,32)
fFrontBtn.Text = "Front"
fFrontBtn.Font = Enum.Font.Gotham

-- Mix Mode UI (Walk+Look)
local mixWalkLabel = Instance.new("TextLabel", pageUni)
mixWalkLabel.Position = UDim2.new(0,380,0,196)
mixWalkLabel.Size = UDim2.new(0,260,0,20)
mixWalkLabel.BackgroundTransparency = 1
mixWalkLabel.Font = Enum.Font.GothamBold
mixWalkLabel.Text = "Mix Mode Walk+Look (applies when both active):"

local mWalkNormal = Instance.new("TextButton", pageUni)
mWalkNormal.Position = UDim2.new(0,380,0,220)
mWalkNormal.Size = UDim2.new(0,84,0,28)
mWalkNormal.Text = "Normal"

local mWalkBehind = Instance.new("TextButton", pageUni)
mWalkBehind.Position = UDim2.new(0,472,0,220)
mWalkBehind.Size = UDim2.new(0,84,0,28)
mWalkBehind.Text = "Behind"

local mWalkFront = Instance.new("TextButton", pageUni)
mWalkFront.Position = UDim2.new(0,564,0,220)
mWalkFront.Size = UDim2.new(0,84,0,28)
mWalkFront.Text = "Front"

-- Mix Mode UI (Fly+Look)
local mixFlyLabel = Instance.new("TextLabel", pageUni)
mixFlyLabel.Position = UDim2.new(0,380,0,256)
mixFlyLabel.Size = UDim2.new(0,260,0,20)
mixFlyLabel.BackgroundTransparency = 1
mixFlyLabel.Font = Enum.Font.GothamBold
mixFlyLabel.Text = "Mix Mode Fly+Look (applies when both active):"

local mFlyNormal = Instance.new("TextButton", pageUni)
mFlyNormal.Position = UDim2.new(0,380,0,280)
mFlyNormal.Size = UDim2.new(0,84,0,28)
mFlyNormal.Text = "Normal"

local mFlyBehind = Instance.new("TextButton", pageUni)
mFlyBehind.Position = UDim2.new(0,472,0,280)
mFlyBehind.Size = UDim2.new(0,84,0,28)
mFlyBehind.Text = "Behind"

local mFlyFront = Instance.new("TextButton", pageUni)
mFlyFront.Position = UDim2.new(0,564,0,280)
mFlyFront.Size = UDim2.new(0,84,0,28)
mFlyFront.Text = "Front"

-- Offset setter (shared)
local offsetLbl = Instance.new("TextLabel", pageUni)
offsetLbl.Position = UDim2.new(0,380,0,320)
offsetLbl.Size = UDim2.new(0,200,0,20)
offsetLbl.BackgroundTransparency = 1
offsetLbl.Font = Enum.Font.Gotham
offsetLbl.Text = "Offset (studs for Behind/Front):"

local offsetBox = Instance.new("TextBox", pageUni)
offsetBox.Position = UDim2.new(0,580,0,316)
offsetBox.Size = UDim2.new(0,108,0,28)
offsetBox.Text = tostring(uniOffset)
offsetBox.ClearTextOnFocus = false
offsetBox.Font = Enum.Font.Gotham

-- Universal Look buttons
local uniLookBtn = Instance.new("TextButton", pageUni)
uniLookBtn.Position = UDim2.new(0,8,0,224)
uniLookBtn.Size = UDim2.new(0,360,0,40)
uniLookBtn.Text = "Universal LookAt (nearest) : OFF"
uniLookBtn.Font = Enum.Font.Gotham
uniLookBtn.BackgroundColor3 = Color3.fromRGB(90,90,90)

local uniLookV2Btn = Instance.new("TextButton", pageUni)
uniLookV2Btn.Position = UDim2.new(0,8,0,284)
uniLookV2Btn.Size = UDim2.new(0,360,0,40)
uniLookV2Btn.Text = "Universal LookAtV2 (nearest): OFF"
uniLookV2Btn.Font = Enum.Font.Gotham
uniLookV2Btn.BackgroundColor3 = Color3.fromRGB(90,90,90)

-- player list population
local playerRows = {}
local function makeRow(plr)
    local f = Instance.new("Frame")
    f.Size = UDim2.new(1, -12, 0, 36)
    f.BackgroundColor3 = Color3.fromRGB(30,30,32)
    f.BorderSizePixel = 0
    local name = Instance.new("TextLabel", f)
    name.Size = UDim2.new(0.6, 0, 1, 0)
    name.Position = UDim2.new(0,8,0,0)
    name.BackgroundTransparency = 1
    name.Font = Enum.Font.Gotham
    name.TextSize = 14
    name.Text = plr.Name
    name.TextColor3 = Color3.fromRGB(230,230,230)
    name.TextXAlignment = Enum.TextXAlignment.Left
    local btn = Instance.new("TextButton", f)
    btn.Size = UDim2.new(0,80,0,28)
    btn.Position = UDim2.new(1,-92,0.5,-14)
    btn.Text = "Select"
    btn.Font = Enum.Font.Gotham
    btn.BackgroundColor3 = Color3.fromRGB(70,120,200)
    btn.TextColor3 = Color3.new(1,1,1)
    return {frame = f, name = name, btn = btn}
end

local function refreshPlayers()
    for _,c in ipairs(playerScroll:GetChildren()) do if c:IsA("Frame") then c:Destroy() end end
    playerRows = {}
    for _,p in ipairs(Players:GetPlayers()) do
        if p ~= LocalPlayer then
            local r = makeRow(p)
            r.frame.Parent = playerScroll
            r.btn.MouseButton1Click:Connect(function()
                selectedPlayer = p
                selLabel.Text = "Selected: "..p.Name
                for _,v in pairs(playerRows) do v.frame.BackgroundColor3 = Color3.fromRGB(30,30,32) end
                r.frame.BackgroundColor3 = Color3.fromRGB(45,45,48)
            end)
            playerRows[p] = r
        end
    end
    local count = 0
    for _,c in ipairs(playerScroll:GetChildren()) do if c:IsA("Frame") then count = count + 1 end end
    playerScroll.CanvasSize = UDim2.new(0,0,0, count * 42 + 12)
end

refreshPlayers()
Players.PlayerAdded:Connect(refreshPlayers)
Players.PlayerRemoving:Connect(refreshPlayers)

-- ===== Button behavior & sanitization =====
walkSpeedBox.FocusLost:Connect(function() local v = tonumber(walkSpeedBox.Text) or DEFAULT_CFRAME_WALK_SPEED; walkSpeedBox.Text = tostring(math.max(0, v)) end)
walkPredBox.FocusLost:Connect(function() local v = tonumber(walkPredBox.Text) or DEFAULT_PRED; walkPredBox.Text = tostring(math.max(0, v)) end)
lookPredBox.FocusLost:Connect(function() local v = tonumber(lookPredBox.Text) or DEFAULT_LOOK_PRED; lookPredBox.Text = tostring(math.max(0, v)) end)
lookV2PredBox.FocusLost:Connect(function() local v = tonumber(lookV2PredBox.Text) or DEFAULT_LOOKV2_PRED; lookV2PredBox.Text = tostring(math.max(0, v)) end)
flySpeedBox.FocusLost:Connect(function() local v = tonumber(flySpeedBox.Text) or DEFAULT_BV_SPEED; flySpeedBox.Text = tostring(math.max(0, v)) end)
flyPredBox.FocusLost:Connect(function() local v = tonumber(flyPredBox.Text) or DEFAULT_PRED; flyPredBox.Text = tostring(math.max(0, v)) end)
aboveBox.FocusLost:Connect(function() aboveBox.Text = tostring(math.max(0, tonumber(aboveBox.Text) or 8)) end)
aboveTweenBox.FocusLost:Connect(function() aboveTweenBox.Text = tostring(math.max(1e-4, tonumber(aboveTweenBox.Text) or DEFAULT_ABOVE_TWEEN)) end)
offsetBox.FocusLost:Connect(function() uniOffset = math.max(0, tonumber(offsetBox.Text) or uniOffset); offsetBox.Text = tostring(uniOffset) end)

-- CFrame Walk toggle
cwalkBtn.MouseButton1Click:Connect(function()
    cframeWalkActive = not cframeWalkActive
    cwalkBtn.Text = cframeWalkActive and "CFrame Walk (to selected): ON" or "CFrame Walk (to selected): OFF"
    cwalkBtn.BackgroundColor3 = cframeWalkActive and Color3.fromRGB(160,60,60) or Color3.fromRGB(90,90,90)
    if cframeWalkActive then
        universalForwardActive = false; uniForwardBtn.Text = "Universal Forward CFrame-Walk (HRP facing): OFF"; uniForwardBtn.BackgroundColor3 = Color3.fromRGB(90,90,90)
        universalWalkToPlayersActive = false; uniToPlayersBtn.Text = "Universal Walk-To-Nearest Player: OFF"; uniToPlayersBtn.BackgroundColor3 = Color3.fromRGB(90,90,90)
        universalAutoFly = false; uniAutoFlyBtn.Text = "Universal AutoFly (BV to nearest): OFF"; uniAutoFlyBtn.BackgroundColor3 = Color3.fromRGB(90,90,90)
        flyActive = false; flyBtn.Text = "Fly (BV to selected): OFF"; flyBtn.BackgroundColor3 = Color3.fromRGB(90,90,90)
        removeControllers()
    end
end)

uniForwardBtn.MouseButton1Click:Connect(function()
    universalForwardActive = not universalForwardActive
    uniForwardBtn.Text = universalForwardActive and "Universal Forward CFrame-Walk (HRP facing): ON" or "Universal Forward CFrame-Walk (HRP facing): OFF"
    uniForwardBtn.BackgroundColor3 = universalForwardActive and Color3.fromRGB(160,60,60) or Color3.fromRGB(90,90,90)
    if universalForwardActive then
        cframeWalkActive = false; cwalkBtn.Text = "CFrame Walk (to selected): OFF"; cwalkBtn.BackgroundColor3 = Color3.fromRGB(90,90,90)
        if not universalAutoFly and not flyActive then removeControllers() end
    end
end)

uniToPlayersBtn.MouseButton1Click:Connect(function()
    universalWalkToPlayersActive = not universalWalkToPlayersActive
    uniToPlayersBtn.Text = universalWalkToPlayersActive and "Universal Walk-To-Nearest Player: ON" or "Universal Walk-To-Nearest Player: OFF"
    uniToPlayersBtn.BackgroundColor3 = universalWalkToPlayersActive and Color3.fromRGB(160,60,60) or Color3.fromRGB(90,90,90)
    if universalWalkToPlayersActive then
        cframeWalkActive = false; cwalkBtn.Text = "CFrame Walk (to selected): OFF"; cwalkBtn.BackgroundColor3 = Color3.fromRGB(90,90,90)
        universalForwardActive = false; uniForwardBtn.Text = "Universal Forward CFrame-Walk (HRP facing): OFF"; uniForwardBtn.BackgroundColor3 = Color3.fromRGB(90,90,90)
        if not universalAutoFly and not flyActive then removeControllers() end
    end
end)

uniAutoFlyBtn.MouseButton1Click:Connect(function()
    universalAutoFly = not universalAutoFly
    uniAutoFlyBtn.Text = universalAutoFly and "Universal AutoFly (BV to nearest): ON" or "Universal AutoFly (BV to nearest): OFF"
    uniAutoFlyBtn.BackgroundColor3 = universalAutoFly and Color3.fromRGB(160,60,60) or Color3.fromRGB(90,90,90)
    if universalAutoFly then
        ensureControllers()
        universalForwardActive = false; uniForwardBtn.Text = "Universal Forward CFrame-Walk (HRP facing): OFF"; uniForwardBtn.BackgroundColor3 = Color3.fromRGB(90,90,90)
        universalWalkToPlayersActive = false; uniToPlayersBtn.Text = "Universal Walk-To-Nearest Player: OFF"; uniToPlayersBtn.BackgroundColor3 = Color3.fromRGB(90,90,90)
    else
        if not flyActive and not aboveActive then removeControllers() end
    end
end)

flyBtn.MouseButton1Click:Connect(function()
    flyActive = not flyActive
    flyBtn.Text = flyActive and "Fly (BV to selected): ON" or "Fly (BV to selected): OFF"
    flyBtn.BackgroundColor3 = flyActive and Color3.fromRGB(160,60,60) or Color3.fromRGB(90,90,90)
    if flyActive then
        ensureControllers()
        cframeWalkActive = false; cwalkBtn.Text = "CFrame Walk (to selected): OFF"; cwalkBtn.BackgroundColor3 = Color3.fromRGB(90,90,90)
        universalForwardActive = false; uniForwardBtn.Text = "Universal Forward CFrame-Walk (HRP facing): OFF"; uniForwardBtn.BackgroundColor3 = Color3.fromRGB(90,90,90)
        universalWalkToPlayersActive = false; uniToPlayersBtn.Text = "Universal Walk-To-Nearest Player: OFF"; uniToPlayersBtn.BackgroundColor3 = Color3.fromRGB(90,90,90)
    else
        if not universalAutoFly and not aboveActive then removeControllers() end
    end
end)

-- Above toggle (tween)
local aboveThread = nil
aboveBtn.MouseButton1Click:Connect(function()
    aboveActive = not aboveActive
    aboveBtn.Text = aboveActive and "Above: ON" or "Above: OFF"
    aboveBtn.BackgroundColor3 = aboveActive and Color3.fromRGB(160,60,60) or Color3.fromRGB(90,90,90)
    if aboveActive then
        cframeWalkActive = false; cwalkBtn.Text = "CFrame Walk (to selected): OFF"; cwalkBtn.BackgroundColor3 = Color3.fromRGB(90,90,90)
        universalForwardActive = false; uniForwardBtn.Text = "Universal Forward CFrame-Walk (HRP facing): OFF"; uniForwardBtn.BackgroundColor3 = Color3.fromRGB(90,90,90)
        universalWalkToPlayersActive = false; uniToPlayersBtn.Text = "Universal Walk-To-Nearest Player: OFF"; uniToPlayersBtn.BackgroundColor3 = Color3.fromRGB(90,90,90)
        flyActive = false; flyBtn.Text = "Fly (BV to selected): OFF"; flyBtn.BackgroundColor3 = Color3.fromRGB(90,90,90)
        universalAutoFly = false; uniAutoFlyBtn.Text = "Universal AutoFly (BV to nearest): OFF"; uniAutoFlyBtn.BackgroundColor3 = Color3.fromRGB(90,90,90)

        if aboveThread then aboveThread = nil end
        aboveThread = task.spawn(function()
            while aboveActive and screenGui.Parent do
                if selectedPlayer and isAlive(selectedPlayer) then
                    local tgt = bestPart(selectedPlayer)
                    if tgt then
                        local height = tonumber(aboveBox.Text) or 8
                        local tweenTime = tonumber(aboveTweenBox.Text) or DEFAULT_ABOVE_TWEEN
                        tweenTime = math.max(1e-4, tweenTime)
                        local abovePos = Vector3.new(tgt.Position.X, tgt.Position.Y + height, tgt.Position.Z)
                        local desiredCFrame = CFrame.new(abovePos, tgt.Position)
                        local char = LocalPlayer.Character
                        local hrp = char and (char:FindFirstChild("HumanoidRootPart") or char:FindFirstChild("UpperTorso") or char:FindFirstChild("Torso"))
                        if hrp then
                            local ok, tw = pcall(function()
                                return TweenService:Create(hrp, TweenInfo.new(tweenTime, Enum.EasingStyle.Linear, Enum.EasingDirection.Out), {CFrame = desiredCFrame})
                            end)
                            if ok and tw then
                                tw:Play()
                                local waited = 0
                                while waited < tweenTime and tw.PlaybackState == Enum.PlaybackState.Playing and aboveActive do
                                    task.wait(math.min(0.03, tweenTime))
                                    waited = waited + 0.03
                                end
                                pcall(function() hrp.CFrame = desiredCFrame end)
                            else
                                pcall(function() hrp.CFrame = desiredCFrame end)
                                task.wait(0.05)
                            end
                        end
                    else
                        task.wait(0.12)
                    end
                else
                    task.wait(0.15)
                end
            end
        end)
    else
        aboveThread = nil
    end
end)

-- look toggles (per-target)
lookBtn.MouseButton1Click:Connect(function()
    lookActive = not lookActive
    lookBtn.Text = lookActive and "LookAt (XY): ON" or "LookAt (XY): OFF"
    lookBtn.BackgroundColor3 = lookActive and Color3.fromRGB(160,60,60) or Color3.fromRGB(90,90,90)
    if lookActive then
        universalLook = false; uniLookBtn.Text = "Universal LookAt (nearest) : OFF"; uniLookBtn.BackgroundColor3 = Color3.fromRGB(90,90,90)
        lookV2Active = false; lookV2Btn.Text = "LookAtV2 (XYZ+Roll): OFF"; lookV2Btn.BackgroundColor3 = Color3.fromRGB(90,90,90)
    end
end)

lookV2Btn.MouseButton1Click:Connect(function()
    lookV2Active = not lookV2Active
    lookV2Btn.Text = lookV2Active and "LookAtV2 (XYZ+Roll): ON" or "LookAtV2 (XYZ+Roll): OFF"
    lookV2Btn.BackgroundColor3 = lookV2Active and Color3.fromRGB(160,60,60) or Color3.fromRGB(90,90,90)
    if lookV2Active then
        universalLookV2 = false; uniLookV2Btn.Text = "Universal LookAtV2 (nearest): OFF"; uniLookV2Btn.BackgroundColor3 = Color3.fromRGB(90,90,90)
        lookActive = false; lookBtn.Text = "LookAt (XY): OFF"; lookBtn.BackgroundColor3 = Color3.fromRGB(90,90,90)
    end
end)

-- Universal Look toggles
uniLookBtn.MouseButton1Click:Connect(function()
    universalLook = not universalLook
    uniLookBtn.Text = universalLook and "Universal LookAt (nearest) : ON" or "Universal LookAt (nearest) : OFF"
    uniLookBtn.BackgroundColor3 = universalLook and Color3.fromRGB(160,60,60) or Color3.fromRGB(90,90,90)
    if universalLook then
        lookActive = false; lookBtn.Text = "LookAt (XY): OFF"; lookBtn.BackgroundColor3 = Color3.fromRGB(90,90,90)
        universalLookV2 = false; uniLookV2Btn.Text = "Universal LookAtV2 (nearest): OFF"; uniLookV2Btn.BackgroundColor3 = Color3.fromRGB(90,90,90)
    end
end)

uniLookV2Btn.MouseButton1Click:Connect(function()
    universalLookV2 = not universalLookV2
    uniLookV2Btn.Text = universalLookV2 and "Universal LookAtV2 (nearest): ON" or "Universal LookAtV2 (nearest): OFF"
    uniLookV2Btn.BackgroundColor3 = universalLookV2 and Color3.fromRGB(160,60,60) or Color3.fromRGB(90,90,90)
    if universalLookV2 then
        lookV2Active = false; lookV2Btn.Text = "LookAtV2 (XYZ+Roll): OFF"; lookV2Btn.BackgroundColor3 = Color3.fromRGB(90,90,90)
        universalLook = false; uniLookBtn.Text = "Universal LookAt (nearest) : OFF"; uniLookBtn.BackgroundColor3 = Color3.fromRGB(90,90,90)
    end
end)

-- Combat / Mix mode handlers (kept same)
local function updateCFrameModeUI()
    cNormalBtn.BackgroundColor3 = (uniCFrameMode == "Normal") and Color3.fromRGB(160,160,160) or Color3.fromRGB(70,70,70)
    cBehindBtn.BackgroundColor3 = (uniCFrameMode == "Behind") and Color3.fromRGB(160,160,160) or Color3.fromRGB(70,70,70)
    cFrontBtn.BackgroundColor3 = (uniCFrameMode == "Front") and Color3.fromRGB(160,160,160) or Color3.fromRGB(70,70,70)
end
cNormalBtn.MouseButton1Click:Connect(function() uniCFrameMode = "Normal"; updateCFrameModeUI() end)
cBehindBtn.MouseButton1Click:Connect(function() uniCFrameMode = "Behind"; updateCFrameModeUI() end)
cFrontBtn.MouseButton1Click:Connect(function() uniCFrameMode = "Front"; updateCFrameModeUI() end)
updateCFrameModeUI()

local function updateFlyModeUI()
    fNormalBtn.BackgroundColor3 = (uniFlyMode == "Normal") and Color3.fromRGB(160,160,160) or Color3.fromRGB(70,70,70)
    fBehindBtn.BackgroundColor3 = (uniFlyMode == "Behind") and Color3.fromRGB(160,160,160) or Color3.fromRGB(70,70,70)
    fFrontBtn.BackgroundColor3 = (uniFlyMode == "Front") and Color3.fromRGB(160,160,160) or Color3.fromRGB(70,70,70)
end
fNormalBtn.MouseButton1Click:Connect(function() uniFlyMode = "Normal"; updateFlyModeUI() end)
fBehindBtn.MouseButton1Click:Connect(function() uniFlyMode = "Behind"; updateFlyModeUI() end)
fFrontBtn.MouseButton1Click:Connect(function() uniFlyMode = "Front"; updateFlyModeUI() end)
updateFlyModeUI()

local function updateMixWalkUI()
    mWalkNormal.BackgroundColor3 = (uniMixWalkMode == "Normal") and Color3.fromRGB(160,160,160) or Color3.fromRGB(70,70,70)
    mWalkBehind.BackgroundColor3 = (uniMixWalkMode == "Behind") and Color3.fromRGB(160,160,160) or Color3.fromRGB(70,70,70)
    mWalkFront.BackgroundColor3 = (uniMixWalkMode == "Front") and Color3.fromRGB(160,160,160) or Color3.fromRGB(70,70,70)
end
mWalkNormal.MouseButton1Click:Connect(function() uniMixWalkMode = "Normal"; updateMixWalkUI() end)
mWalkBehind.MouseButton1Click:Connect(function() uniMixWalkMode = "Behind"; updateMixWalkUI() end)
mWalkFront.MouseButton1Click:Connect(function() uniMixWalkMode = "Front"; updateMixWalkUI() end)
updateMixWalkUI()

local function updateMixFlyUI()
    mFlyNormal.BackgroundColor3 = (uniMixFlyMode == "Normal") and Color3.fromRGB(160,160,160) or Color3.fromRGB(70,70,70)
    mFlyBehind.BackgroundColor3 = (uniMixFlyMode == "Behind") and Color3.fromRGB(160,160,160) or Color3.fromRGB(70,70,70)
    mFlyFront.BackgroundColor3 = (uniMixFlyMode == "Front") and Color3.fromRGB(160,160,160) or Color3.fromRGB(70,70,70)
end
mFlyNormal.MouseButton1Click:Connect(function() uniMixFlyMode = "Normal"; updateMixFlyUI() end)
mFlyBehind.MouseButton1Click:Connect(function() uniMixFlyMode = "Behind"; updateMixFlyUI() end)
mFlyFront.MouseButton1Click:Connect(function() uniMixFlyMode = "Front"; updateMixFlyUI() end)
updateMixFlyUI()

-- tabs
t1.MouseButton1Click:Connect(function() pageMain.Visible = true; pageUni.Visible = false; t1.BackgroundColor3 = Color3.fromRGB(60,60,60); t2.BackgroundColor3 = Color3.fromRGB(36,36,40) end)
t2.MouseButton1Click:Connect(function() pageMain.Visible = false; pageUni.Visible = true; t2.BackgroundColor3 = Color3.fromRGB(60,60,60); t1.BackgroundColor3 = Color3.fromRGB(36,36,40) end)

-- close
closeBtn.MouseButton1Click:Connect(function()
    cframeWalkActive = false
    universalForwardActive = false
    universalWalkToPlayersActive = false
    universalAutoFly = false
    flyActive = false
    aboveActive = false
    universalLook = false
    universalLookV2 = false
    removeControllers()
    screenGui:Destroy()
end)

-- drag GUI
do
    local dragging, dragStart, startPos = false, nil, nil
    header.InputBegan:Connect(function(input)
        if input.UserInputType == Enum.UserInputType.MouseButton1 then
            dragging = true
            dragStart = input.Position
            startPos = main.Position
            input.Changed:Connect(function()
                if input.UserInputState == Enum.UserInputState.End then dragging = false end
            end)
        end
    end)
    header.InputChanged:Connect(function(input)
        if dragging and input.UserInputType == Enum.UserInputType.MouseMovement then
            local delta = input.Position - dragStart
            main.Position = UDim2.new(startPos.X.Scale, startPos.X.Offset + delta.X, startPos.Y.Scale, startPos.Y.Offset + delta.Y)
        end
    end)
end

-- ===== RenderStepped loop (per-frame) =====
RunService.RenderStepped:Connect(function(dt)
    local now = tick()
    -- update prediction states for all players
    for _,p in ipairs(Players:GetPlayers()) do updatePlayerState(p, now) end

    -- ===== CFrame Walk toward selected (target) =====
    if cframeWalkActive and selectedPlayer and isAlive(selectedPlayer) then
        local hrp = LocalPlayer.Character and (LocalPlayer.Character:FindFirstChild("HumanoidRootPart")
                    or LocalPlayer.Character:FindFirstChild("UpperTorso") or LocalPlayer.Character:FindFirstChild("Torso"))
        if hrp then
            local stepDist = tonumber(walkSpeedBox.Text) or DEFAULT_CFRAME_WALK_SPEED
            local desired = computeOffsetTarget(selectedPlayer, uniCFrameMode, uniOffset, false, tonumber(walkPredBox.Text) or DEFAULT_PRED)
            if desired then
                cframeStepTowardsExact(hrp, desired, stepDist)
            end
        end
    end

    -- ===== Universal Forward (horizontal) CFrame-walk using HRP facing (not camera) =====
    if universalForwardActive then
        local hrp = LocalPlayer.Character and (LocalPlayer.Character:FindFirstChild("HumanoidRootPart")
                    or LocalPlayer.Character:FindFirstChild("UpperTorso") or LocalPlayer.Character:FindFirstChild("Torso"))
        if hrp then
            local stepDist = tonumber(walkSpeedBox.Text) or DEFAULT_CFRAME_WALK_SPEED
            cframeMoveForwardHorizontalExact_ByHRP(hrp, stepDist)
        end
    end

    -- ===== Universal Walk-To-Nearest Player (CFrame-walk with pred & combat mode) =====
    if universalWalkToPlayersActive then
        local nearest = getNearestAlivePlayerToMe()
        local hrp = LocalPlayer.Character and (LocalPlayer.Character:FindFirstChild("HumanoidRootPart")
                    or LocalPlayer.Character:FindFirstChild("UpperTorso") or LocalPlayer.Character:FindFirstChild("Torso"))
        if hrp and nearest and isAlive(nearest) then
            local desired = computeOffsetTarget(nearest, uniCFrameMode, uniOffset, false, tonumber(walkPredBox.Text) or DEFAULT_PRED)
            if desired then
                local stepDist = tonumber(walkSpeedBox.Text) or DEFAULT_CFRAME_WALK_SPEED
                cframeStepTowardsExact(hrp, desired, stepDist)
            end
        end
    end

    -- ===== Fly (BV) toward selected with prediction & combat mode =====
    if flyActive and selectedPlayer and isAlive(selectedPlayer) then
        local desired = computeOffsetTarget(selectedPlayer, uniFlyMode, uniOffset, true, tonumber(flyPredBox.Text) or DEFAULT_PRED)
        if desired then
            local bvSpeed = tonumber(flySpeedBox.Text) or DEFAULT_BV_SPEED
            flyTowardPositionBV(desired, bvSpeed)
        end
    end

    -- ===== Universal AutoFly toward nearest with prediction & combat mode =====
    if universalAutoFly then
        local nearest = getNearestAlivePlayerToMe()
        if nearest and isAlive(nearest) then
            local desired = computeOffsetTarget(nearest, uniFlyMode, uniOffset, true, tonumber(flyPredBox.Text) or DEFAULT_PRED)
            if desired then
                local bvSpeed = tonumber(flySpeedBox.Text) or DEFAULT_BV_SPEED
                ensureControllers()
                flyTowardPositionBV(desired, bvSpeed)
            end
        end
    end

    -- ===== Look behaviors (NOW use dedicated lookPredBox & lookV2PredBox) =====
    local lookPred = tonumber(lookPredBox.Text) or DEFAULT_LOOK_PRED
    local lookV2Pred = tonumber(lookV2PredBox.Text) or DEFAULT_LOOKV2_PRED

    if lookActive and selectedPlayer and isAlive(selectedPlayer) then
        -- Previously we used computeOffsetTarget (which applied Behind/Front offsets).
        -- Per request: always look at the target (predicted position) only — not the offset target.
        local tgt = predictedPosition(selectedPlayer, lookPred)
        if tgt then pcall(function() doLookAtPositionXY(tgt) end) end
    end

    if lookV2Active and selectedPlayer and isAlive(selectedPlayer) then
        -- Always look at predicted target position for LookAtV2 as well.
        local tgt = predictedPosition(selectedPlayer, lookV2Pred)
        if tgt then pcall(function() doLookAtPositionV2(tgt, 0) end) end
    end

    if universalLook then
        local nearest = getNearestAlivePlayerToMe()
        if nearest and isAlive(nearest) then
            -- Always look at the predicted position for universal look (no Behind/Front offsets).
            local tgt = predictedPosition(nearest, lookPred)
            if tgt then pcall(function() doLookAtPositionXY(tgt) end) end
        end
    end

    if universalLookV2 then
        local nearest = getNearestAlivePlayerToMe()
        if nearest and isAlive(nearest) then
            -- Always look at predicted position for universal LookAtV2 as well.
            local tgt = predictedPosition(nearest, lookV2Pred)
            if tgt then pcall(function() doLookAtPositionV2(tgt, 0) end) end
        end
    end

    -- ===== Anti-stuck nudge (CFrame walk modes) =====
    local myHRP = LocalPlayer.Character and (LocalPlayer.Character:FindFirstChild("HumanoidRootPart")
                or LocalPlayer.Character:FindFirstChild("UpperTorso") or LocalPlayer.Character:FindFirstChild("Torso"))
    if myHRP then
        if not lastMyPos then lastMyPos = myHRP.Position; lastMovedAt = now end
        if (myHRP.Position - lastMyPos).Magnitude > STUCK_MOVE_EPS then
            lastMovedAt = now
            lastMyPos = myHRP.Position
        else
            local activeCframeModes = cframeWalkActive or universalForwardActive or universalWalkToPlayersActive
            if activeCframeModes and (now - lastMovedAt) > STUCK_TIME_THRESHOLD then
                pcall(function() myHRP.CFrame = myHRP.CFrame + Vector3.new(0, 1.6, 0) end)
                lastMovedAt = now
                lastMyPos = myHRP.Position
            end
        end
    end

    -- cleanup BV controllers when BV modes off
    if not (flyActive or universalAutoFly) then
        if bv and bv.Velocity.Magnitude == 0 then
            removeControllers()
        end
    end
end)

warn("PlayerMover v11 loaded — LookAt and LookAtV2 now always point at the target's predicted position (no Behind/Front offsets).")

Features & Information

basiscally just a gui lookat gui and it might be very confusing to use but once you know how to use it be good but yea. Fly, lookat, lookatv2(look all ways) cframe auto walk, autowalk(i just added that to added that) and mostly prediction and universal page to keep aiming at nearbyplayers also the normal front and back was just made for me to try to make it get behind them and front
#lookat#fly#lookat gui#Universal script#prediction

Community Comments (0)

No comments yet for this script.

More Scripts for Universal Scripts