AND add in an accurate algorithm to track anyone accurately, advanced predictive algorithm, and do some optimizations and debugging with multiple handlers.

```
-- Services
local Players = game:GetService("Players")
local RunService = game:GetService("RunService")
local UserInputService = game:GetService("UserInputService")

-- Configuration
local ROTATION_SPEED = 1.1       -- Speed of the rotation interpolation
local ESP_TEXT = "Targeted"      -- Text displayed in ESP
local ESP_COLOR = Color3.fromRGB(255, 0, 0)  -- Color of the ESP text

-- Variables
local player = Players.LocalPlayer
local character = player.Character or player.CharacterAdded:Wait()
local humanoidRootPart = character:WaitForChild("HumanoidRootPart")
local trackedTarget = nil          -- Currently tracked target (another player)
local espIndicator = nil           -- BillboardGui for ESP

-- Helper Function: Check if a model has a Humanoid
local function hasHumanoid(model)
    return model and model:FindFirstChildOfClass("Humanoid") ~= nil
end

-- Helper Function: Find the closest player to the local player
local function findClosestPlayer()
    local closestPlayer = nil
    local shortestDistance = math.huge

    for _, otherPlayer in ipairs(Players:GetPlayers()) do
        if otherPlayer ~= player and otherPlayer.Character and otherPlayer.Character:FindFirstChild("HumanoidRootPart") then
            local distance = (otherPlayer.Character.HumanoidRootPart.Position - humanoidRootPart.Position).Magnitude
            if distance < shortestDistance then
                shortestDistance = distance
                closestPlayer = otherPlayer
            end
        end
    end

    return closestPlayer
end

-- Function: Toggle Lock-On to the Closest Player when E is pressed
local function toggleLockOn()
    if trackedTarget then
        -- Deselect the current target
        trackedTarget = nil
        if espIndicator then
            espIndicator:Destroy()
            espIndicator = nil
        end
    else
        -- Find and select the closest player
        local closestPlayer = findClosestPlayer()
        if closestPlayer and closestPlayer.Character then
            trackedTarget = closestPlayer.Character
            -- Create ESP indicator
            local targetHead = trackedTarget:FindFirstChild("Head")
            if targetHead then
                -- Ensure previous ESP is removed
                if espIndicator then
                    espIndicator:Destroy()
                    espIndicator = nil
                end

                -- Create BillboardGui for ESP
                espIndicator = Instance.new("BillboardGui")
                espIndicator.Adornee = targetHead
                espIndicator.Size = UDim2.new(0, 100, 0, 50)
                espIndicator.StudsOffset = Vector3.new(0, 2, 0)
                espIndicator.AlwaysOnTop = true
                espIndicator.Name = "TargetESP"

                -- Create TextLabel for ESP
                local textLabel = Instance.new("TextLabel")
                textLabel.Parent = espIndicator
                textLabel.Size = UDim2.new(1, 0, 1, 0)
                textLabel.BackgroundTransparency = 1
                textLabel.Text = ESP_TEXT
                textLabel.TextColor3 = ESP_COLOR
                textLabel.Font = Enum.Font.SourceSansBold
                textLabel.TextScaled = true
                textLabel.TextStrokeTransparency = 0.8

                -- Parent the ESP to the player's PlayerGui
                espIndicator.Parent = player:WaitForChild("PlayerGui")
            end
        end
    end
end

-- Function: Smoothly rotate to face the tracked target
local function smoothRotateToTarget()
    if trackedTarget and trackedTarget:FindFirstChild("HumanoidRootPart") then
        local targetPart = trackedTarget.HumanoidRootPart
        local targetPosition = Vector3.new(targetPart.Position.X, humanoidRootPart.Position.Y, targetPart.Position.Z)
        local direction = (targetPosition - humanoidRootPart.Position).Unit
        local desiredCFrame = CFrame.new(humanoidRootPart.Position, targetPosition)

        -- Advanced Lerp for smooth 360° rotation
        humanoidRootPart.CFrame = humanoidRootPart.CFrame:Lerp(desiredCFrame, ROTATION_SPEED)
    end
end

-- Event Listener: Detect when E key is pressed
UserInputService.InputBegan:Connect(function(input, gameProcessed)
    if gameProcessed then return end

    if input.KeyCode == Enum.KeyCode.E then
        toggleLockOn()
    end
end)

-- Event Listener: Handle character respawn
player.CharacterAdded:Connect(function(newCharacter)
    character = newCharacter
    humanoidRootPart = character:WaitForChild("HumanoidRootPart")
    -- Reset tracking and ESP on respawn
    trackedTarget = nil
    if espIndicator then
        espIndicator:Destroy()
        espIndicator = nil
    end
end)

-- Render Step: Continuously update rotation if a target is tracked
RunService.RenderStepped:Connect(function()
    if trackedTarget then
        smoothRotateToTarget()
    end
end)