Skip to content
TheChatArchiveThe Chat Archive
o1-mini-2024-09-12· OpenAIAi2 WildChat-4.8M (AI2)

Further enhance and add in super-tracking with advanced no-latency and no stutter. AND…

  1. User

    Further enhance and add in super-tracking with advanced no-latency and no stutter. AND make it support shiftlock so that when pressed shiftlock it'll lock the camera to the person but when unshiftlock it'll revert back.

    -- Services
    local Players = game:GetService("Players")
    local RunService = game:GetService("RunService")
    local UserInputService = game:GetService("UserInputService")
    local Workspace = game:GetService("Workspace")
    local TweenService = game:GetService("TweenService")
    
    -- Configuration
    local ROTATION_SPEED = 1.1  -- Smooth rotation speed
    local LOCK_KEY = Enum.KeyCode.E  -- Key to press for lock-on
    local MAX_LOCK_DISTANCE = 10  -- Maximum distance to search for targets
    
    -- Player and Character
    local player = Players.LocalPlayer
    local character = player.Character or player.CharacterAdded:Wait()
    local humanoidRootPart = character:WaitForChild("HumanoidRootPart")
    
    -- Variables
    local TRACKED_MODEL = nil    -- Currently tracked model
    local ESP_BILLBOARD = nil    -- Reference to the ESP BillboardGui
    local SELECTED_PART = "Head"  -- Default selected part
    
    -- Parts List
    local PARTS = {"Torso", "Head", "Left Arm", "Right Arm", "Left Leg", "Right Leg"}
    
    -- Function to create the aesthetic GUI
    local function createLockOnGUI()
        -- Create ScreenGui
        local screenGui = Instance.new("ScreenGui")
        screenGui.Name = "LockOnGUI"
        screenGui.ResetOnSpawn = false
        screenGui.IgnoreGuiInset = true
        screenGui.Parent = player:WaitForChild("PlayerGui")
    
        -- Create main Frame
        local mainFrame = Instance.new("Frame")
        mainFrame.Name = "MainFrame"
        mainFrame.Size = UDim2.new(0, 220, 0, 360)
        mainFrame.Position = UDim2.new(0.05, 0, 0.3, 0)  -- Adjust position as needed
        mainFrame.BackgroundColor3 = Color3.fromRGB(30, 30, 30)
        mainFrame.BackgroundTransparency = 0.2
        mainFrame.BorderSizePixel = 0
        mainFrame.Parent = screenGui
    
        -- Title
        local title = Instance.new("TextLabel")
        title.Name = "Title"
        title.Size = UDim2.new(1, 0, 0, 50)
        title.Position = UDim2.new(0, 0, 0, 0)
        title.BackgroundTransparency = 1
        title.Text = "Lock-On Parts"
        title.Font = Enum.Font.GothamBold
        title.TextSize = 24
        title.TextColor3 = Color3.fromRGB(255, 255, 255)
        title.TextStrokeColor3 = Color3.fromRGB(0, 0, 0)
        title.TextStrokeTransparency = 0.7
        title.Parent = mainFrame
    
        -- Divider Line
        local divider = Instance.new("Frame")
        divider.Size = UDim2.new(1, 0, 0, 2)
        divider.Position = UDim2.new(0, 0, 0, 50)
        divider.BackgroundColor3 = Color3.fromRGB(70, 70, 70)
        divider.BorderSizePixel = 0
        divider.Parent = mainFrame
    
        -- Create buttons for each part
        for index, partName in ipairs(PARTS) do
            local button = Instance.new("TextButton")
            button.Name = partName .. "Button"
            button.Size = UDim2.new(1, -20, 0, 40)
            button.Position = UDim2.new(0, 10, 0, 60 + (index - 1) * 50)
            button.BackgroundColor3 = Color3.fromRGB(50, 50, 50)
            button.BackgroundTransparency = 0.3
            button.BorderSizePixel = 0
            button.Font = Enum.Font.Gotham
            button.Text = partName
            button.TextSize = 18
            button.TextColor3 = Color3.fromRGB(255, 255, 255)
            button.Parent = mainFrame
    
            -- Highlight selected button
            local function updateButtonHighlight()
                if SELECTED_PART == partName then
                    button.BackgroundColor3 = Color3.fromRGB(70, 130, 180)  -- Steel Blue
                    button.TextColor3 = Color3.fromRGB(255, 255, 255)
                else
                    button.BackgroundColor3 = Color3.fromRGB(50, 50, 50)
                    button.TextColor3 = Color3.fromRGB(255, 255, 255)
                end
            end
    
            updateButtonHighlight()
    
            -- Button click event
            button.MouseButton1Click:Connect(function()
                SELECTED_PART = partName
                -- Update all buttons' highlights
                for _, btn in ipairs(mainFrame:GetChildren()) do
                    if btn:IsA("TextButton") then
                        btn.BackgroundColor3 = Color3.fromRGB(50, 50, 50)
                    end
                end
                updateButtonHighlight()
            end)
    
            -- Add hover effect
            button.MouseEnter:Connect(function()
                if SELECTED_PART ~= partName then
                    TweenService:Create(button, TweenInfo.new(0.2), {BackgroundColor3 = Color3.fromRGB(60, 60, 60)}):Play()
                end
            end)
    
            button.MouseLeave:Connect(function()
                if SELECTED_PART ~= partName then
                    TweenService:Create(button, TweenInfo.new(0.2), {BackgroundColor3 = Color3.fromRGB(50, 50, 50)}):Play()
                end
            end)
        end
    end
    
    -- Function to handle selecting/deselecting a target
    local function toggleTarget(target, selectedPart)
        if TRACKED_MODEL == target then
            -- Deselect if the same target is clicked again
            TRACKED_MODEL = nil
            if ESP_BILLBOARD then
                ESP_BILLBOARD:Destroy()
                ESP_BILLBOARD = nil
            end
        else
            -- Select the new target
            TRACKED_MODEL = target
    
            -- Remove existing ESP if any
            if ESP_BILLBOARD then
                ESP_BILLBOARD:Destroy()
                ESP_BILLBOARD = nil
            end
    
            -- Determine RigType
            local rigType = target:FindFirstChildOfClass("Humanoid") and target.Humanoid.RigType or Enum.HumanoidRigType.R6
    
            -- Function to map selected part based on RigType
            local function getMappedPart(partName)
                if rigType == Enum.HumanoidRigType.R15 then
                    local mapping = {
                        ["Torso"] = "UpperTorso",
                        ["Head"] = "Head",
                        ["Left Arm"] = "LeftUpperArm",
                        ["Right Arm"] = "RightUpperArm",
                        ["Left Leg"] = "LeftUpperLeg",
                        ["Right Leg"] = "RightUpperLeg",
                    }
                    return target:FindFirstChild(mapping[partName]) or target:FindFirstChild(partName)
                else -- R6
                    return target:FindFirstChild(partName)
                end
            end
    
            -- Get the specific part based on selection and RigType
            local targetPart = getMappedPart(selectedPart)
    
            if targetPart then
                -- Create ESP for the selected part
                ESP_BILLBOARD = Instance.new("BillboardGui")
                ESP_BILLBOARD.Adornee = targetPart
                ESP_BILLBOARD.Size = UDim2.new(0, 100, 0, 50)
                ESP_BILLBOARD.StudsOffset = Vector3.new(0, 2, 0)
                ESP_BILLBOARD.AlwaysOnTop = true
                ESP_BILLBOARD.Name = "TargetESP"
    
                local textLabel = Instance.new("TextLabel")
                textLabel.Size = UDim2.new(1, 0, 1, 0)
                textLabel.Text = "Targeted: " .. selectedPart
                textLabel.TextColor3 = Color3.fromRGB(255, 215, 0)  -- Gold color
                textLabel.BackgroundTransparency = 1
                textLabel.TextStrokeTransparency = 0.8
                textLabel.Font = Enum.Font.SourceSansBold
                textLabel.TextScaled = true
                textLabel.Parent = ESP_BILLBOARD
    
                ESP_BILLBOARD.Parent = player:WaitForChild("PlayerGui")
            else
                -- Notify if the selected part doesn't exist
                TRACKED_MODEL = nil
                -- Optional: Add a notification here
            end
        end
    end
    
    -- Function to find the nearest humanoid
    local function findNearestHumanoid()
        local closestDistance = MAX_LOCK_DISTANCE
        local nearestHumanoid = nil
    
        for _, otherPlayer in ipairs(Players:GetPlayers()) do
            if otherPlayer ~= player and otherPlayer.Character and otherPlayer.Character:FindFirstChild("HumanoidRootPart") and otherPlayer.Character:FindFirstChild("Humanoid") then
                local distance = (humanoidRootPart.Position - otherPlayer.Character.HumanoidRootPart.Position).Magnitude
                if distance < closestDistance then
                    closestDistance = distance
                    nearestHumanoid = otherPlayer.Character
                end
            end
        end
    
        return nearestHumanoid
    end
    
    -- Function to smoothly face the target's selected part
    local function smoothFaceTarget(target)
        if target and TRACKED_MODEL and TRACKED_MODEL:FindFirstChild("HumanoidRootPart") then
            -- Determine RigType
            local rigType = target:FindFirstChildOfClass("Humanoid") and target.Humanoid.RigType or Enum.HumanoidRigType.R6
    
            -- Function to map selected part based on RigType
            local function getMappedPart(partName)
                if rigType == Enum.HumanoidRigType.R15 then
                    local mapping = {
                        ["Torso"] = "UpperTorso",
                        ["Head"] = "Head",
                        ["Left Arm"] = "LeftUpperArm",
                        ["Right Arm"] = "RightUpperArm",
                        ["Left Leg"] = "LeftUpperLeg",
                        ["Right Leg"] = "RightUpperLeg",
                    }
                    return target:FindFirstChild(mapping[partName]) or target:FindFirstChild(partName)
                else -- R6
                    return target:FindFirstChild(partName)
                end
            end
    
            -- Get the specific part based on selection and RigType
            local targetPart = getMappedPart(SELECTED_PART)
    
            if targetPart then
                local targetPosition = Vector3.new(
                    targetPart.Position.X,
                    humanoidRootPart.Position.Y,
                    targetPart.Position.Z
                )
                local targetCFrame = CFrame.lookAt(humanoidRootPart.Position, targetPosition)
    
                -- Smoothly interpolate the humanoid's CFrame towards the target
                humanoidRootPart.CFrame = humanoidRootPart.CFrame:Lerp(targetCFrame, ROTATION_SPEED)
            end
        end
    end
    
    -- Function to handle key press for lock-on
    local function onKeyPressed(input, gameProcessed)
        if gameProcessed then return end
        if input.KeyCode == LOCK_KEY then
            if TRACKED_MODEL then
                -- If already tracking a target, deselect it
                toggleTarget(TRACKED_MODEL, SELECTED_PART)
            else
                -- Find and select the nearest humanoid
                local nearest = findNearestHumanoid()
                if nearest then
                    toggleTarget(nearest, SELECTED_PART)
                else
                    -- Optional: Notify the player that no target was found
                    -- Example Notification:
                    -- player:FindFirstChildOfClass("PlayerGui"):SetCore("SendNotification", {
                    --     Title = "Lock-On",
                    --     Text = "No targets nearby!",
                    --     Duration = 2
                    -- })
                end
            end
        end
    end
    
    -- Listen for key presses
    UserInputService.InputBegan:Connect(onKeyPressed)
    
    -- Create the GUI
    createLockOnGUI()
    
    -- Ensure the script continues working when the character respawns
    player.CharacterAdded:Connect(function(newCharacter)
        character = newCharacter
        humanoidRootPart = newCharacter:WaitForChild("HumanoidRootPart")
    
        -- Clean up any existing ESP when the character respawns
        if ESP_BILLBOARD then
            ESP_BILLBOARD:Destroy()
            ESP_BILLBOARD = nil
        end
        TRACKED_MODEL = nil
    end)
    
    -- RunService to update the face tracking smoothly
    RunService.RenderStepped:Connect(function()
        if TRACKED_MODEL then
            smoothFaceTarget(TRACKED_MODEL)
        end
    end)
    
  2. Assistant

    To enhance your existing lock-on script with super-tracking capabilities (ensuring no latency and no stutter) and integrate a ShiftLock feature, we'll make several modifications:

    1. Super-Tracking Enhancements:

      • Optimized Update Loop: Utilize RunService.Heartbeat for more consistent and smoother updates.
      • Interpolation and Smoothing: Implement more refined interpolation techniques to minimize stutter.
    2. ShiftLock Support:

      • Toggle Mechanism: Pressing the Shift key will enable ShiftLock mode, locking the camera to the target. Releasing the Shift key will revert the camera to its default behavior.
      • Camera Manipulation: Override the default camera settings to achieve the desired Lock-On behavior when ShiftLock is active.

    Below is the enhanced script incorporating these features:

    -- Services
    local Players = game:GetService("Players")
    local RunService = game:GetService("RunService")
    local UserInputService = game:GetService("UserInputService")
    local Workspace = game:GetService("Workspace")
    local TweenService = game:GetService("TweenService")
    local GuiService = game:GetService("GuiService")
    local Camera = Workspace.CurrentCamera
    
    -- Configuration
    local ROTATION_SPEED = 0.1  -- Reduced for smoother interpolation
    local LOCK_KEY = Enum.KeyCode.E  -- Key to press for lock-on
    local SHIFT_KEY = Enum.KeyCode.LeftShift  -- Shift key for ShiftLock
    local MAX_LOCK_DISTANCE = 25  -- Increased for better tracking range
    local CAMERA_LERP_SPEED = 0.15  -- Camera interpolation speed
    
    -- Player and Character
    local player = Players.LocalPlayer
    local character = player.Character or player.CharacterAdded:Wait()
    local humanoidRootPart = character:WaitForChild("HumanoidRootPart")
    
    -- Variables
    local TRACKED_MODEL = nil    -- Currently tracked model
    local ESP_BILLBOARD = nil    -- Reference to the ESP BillboardGui
    local SELECTED_PART = "Head"  -- Default selected part
    local SHIFTLOCK_ACTIVE = false  -- ShiftLock state
    
    -- Parts List
    local PARTS = {"Torso", "Head", "Left Arm", "Right Arm", "Left Leg", "Right Leg"}
    
    -- Function to create the aesthetic GUI
    local function createLockOnGUI()
        -- Create ScreenGui
        local screenGui = Instance.new("ScreenGui")
        screenGui.Name = "LockOnGUI"
        screenGui.ResetOnSpawn = false
        screenGui.IgnoreGuiInset = true
        screenGui.Parent = player:WaitForChild("PlayerGui")
    
        -- Create main Frame
        local mainFrame = Instance.new("Frame")
        mainFrame.Name = "MainFrame"
        mainFrame.Size = UDim2.new(0, 220, 0, 360)
        mainFrame.Position = UDim2.new(0.05, 0, 0.3, 0)  -- Adjust position as needed
        mainFrame.BackgroundColor3 = Color3.fromRGB(30, 30, 30)
        mainFrame.BackgroundTransparency = 0.2
        mainFrame.BorderSizePixel = 0
        mainFrame.Parent = screenGui
    
        -- Title
        local title = Instance.new("TextLabel")
        title.Name = "Title"
        title.Size = UDim2.new(1, 0, 0, 50)
        title.Position = UDim2.new(0, 0, 0, 0)
        title.BackgroundTransparency = 1
        title.Text = "Lock-On Parts"
        title.Font = Enum.Font.GothamBold
        title.TextSize = 24
        title.TextColor3 = Color3.fromRGB(255, 255, 255)
        title.TextStrokeColor3 = Color3.fromRGB(0, 0, 0)
        title.TextStrokeTransparency = 0.7
        title.Parent = mainFrame
    
        -- Divider Line
        local divider = Instance.new("Frame")
        divider.Size = UDim2.new(1, 0, 0, 2)
        divider.Position = UDim2.new(0, 0, 0, 50)
        divider.BackgroundColor3 = Color3.fromRGB(70, 70, 70)
        divider.BorderSizePixel = 0
        divider.Parent = mainFrame
    
        -- Create buttons for each part
        for index, partName in ipairs(PARTS) do
            local button = Instance.new("TextButton")
            button.Name = partName .. "Button"
            button.Size = UDim2.new(1, -20, 0, 40)
            button.Position = UDim2.new(0, 10, 0, 60 + (index - 1) * 50)
            button.BackgroundColor3 = Color3.fromRGB(50, 50, 50)
            button.BackgroundTransparency = 0.3
            button.BorderSizePixel = 0
            button.Font = Enum.Font.Gotham
            button.Text = partName
            button.TextSize = 18
            button.TextColor3 = Color3.fromRGB(255, 255, 255)
            button.Parent = mainFrame
    
            -- Highlight selected button
            local function updateButtonHighlight()
                if SELECTED_PART == partName then
                    button.BackgroundColor3 = Color3.fromRGB(70, 130, 180)  -- Steel Blue
                    button.TextColor3 = Color3.fromRGB(255, 255, 255)
                else
                    button.BackgroundColor3 = Color3.fromRGB(50, 50, 50)
                    button.TextColor3 = Color3.fromRGB(255, 255, 255)
                end
            end
    
            updateButtonHighlight()
    
            -- Button click event
            button.MouseButton1Click:Connect(function()
                SELECTED_PART = partName
                -- Update all buttons' highlights
                for _, btn in ipairs(mainFrame:GetChildren()) do
                    if btn:IsA("TextButton") then
                        btn.BackgroundColor3 = Color3.fromRGB(50, 50, 50)
                    end
                end
                updateButtonHighlight()
            end)
    
            -- Add hover effect
            button.MouseEnter:Connect(function()
                if SELECTED_PART ~= partName then
                    TweenService:Create(button, TweenInfo.new(0.2), {BackgroundColor3 = Color3.fromRGB(60, 60, 60)}):Play()
                end
            end)
    
            button.MouseLeave:Connect(function()
                if SELECTED_PART ~= partName then
                    TweenService:Create(button, TweenInfo.new(0.2), {BackgroundColor3 = Color3.fromRGB(50, 50, 50)}):Play()
                end
            end)
        end
    end
    
    -- Function to handle selecting/deselecting a target
    local function toggleTarget(target, selectedPart)
        if TRACKED_MODEL == target then
            -- Deselect if the same target is clicked again
            TRACKED_MODEL = nil
            if ESP_BILLBOARD then
                ESP_BILLBOARD:Destroy()
                ESP_BILLBOARD = nil
            end
        else
            -- Select the new target
            TRACKED_MODEL = target
    
            -- Remove existing ESP if any
            if ESP_BILLBOARD then
                ESP_BILLBOARD:Destroy()
                ESP_BILLBOARD = nil
            end
    
            -- Determine RigType
            local rigType = target:FindFirstChildOfClass("Humanoid") and target.Humanoid.RigType or Enum.HumanoidRigType.R6
    
            -- Function to map selected part based on RigType
            local function getMappedPart(partName)
                if rigType == Enum.HumanoidRigType.R15 then
                    local mapping = {
                        ["Torso"] = "UpperTorso",
                        ["Head"] = "Head",
                        ["Left Arm"] = "LeftUpperArm",
                        ["Right Arm"] = "RightUpperArm",
                        ["Left Leg"] = "LeftUpperLeg",
                        ["Right Leg"] = "RightUpperLeg",
                    }
                    return target:FindFirstChild(mapping[partName]) or target:FindFirstChild(partName)
                else -- R6
                    return target:FindFirstChild(partName)
                end
            end
    
            -- Get the specific part based on selection and RigType
            local targetPart = getMappedPart(selectedPart)
    
            if targetPart then
                -- Create ESP for the selected part
                ESP_BILLBOARD = Instance.new("BillboardGui")
                ESP_BILLBOARD.Adornee = targetPart
                ESP_BILLBOARD.Size = UDim2.new(0, 100, 0, 50)
                ESP_BILLBOARD.StudsOffset = Vector3.new(0, 2, 0)
                ESP_BILLBOARD.AlwaysOnTop = true
                ESP_BILLBOARD.Name = "TargetESP"
    
                local textLabel = Instance.new("TextLabel")
                textLabel.Size = UDim2.new(1, 0, 1, 0)
                textLabel.Text = "Targeted: " .. selectedPart
                textLabel.TextColor3 = Color3.fromRGB(255, 215, 0)  -- Gold color
                textLabel.BackgroundTransparency = 1
                textLabel.TextStrokeTransparency = 0.8
                textLabel.Font = Enum.Font.SourceSansBold
                textLabel.TextScaled = true
                textLabel.Parent = ESP_BILLBOARD
    
                ESP_BILLBOARD.Parent = player:WaitForChild("PlayerGui")
            else
                -- Notify if the selected part doesn't exist
                TRACKED_MODEL = nil
                -- Optional: Add a notification here
            end
        end
    end
    
    -- Function to find the nearest humanoid
    local function findNearestHumanoid()
        local closestDistance = MAX_LOCK_DISTANCE
        local nearestHumanoid = nil
    
        for _, otherPlayer in ipairs(Players:GetPlayers()) do
            if otherPlayer ~= player and otherPlayer.Character and otherPlayer.Character:FindFirstChild("HumanoidRootPart") and otherPlayer.Character:FindFirstChild("Humanoid") and otherPlayer.Character.Humanoid.Health > 0 then
                local distance = (humanoidRootPart.Position - otherPlayer.Character.HumanoidRootPart.Position).Magnitude
                if distance < closestDistance then
                    closestDistance = distance
                    nearestHumanoid = otherPlayer.Character
                end
            end
        end
    
        return nearestHumanoid
    end
    
    -- Function to smoothly face the target's selected part
    local function smoothFaceTarget(target)
        if target and TRACKED_MODEL and TRACKED_MODEL:FindFirstChild("HumanoidRootPart") then
            -- Determine RigType
            local rigType = target:FindFirstChildOfClass("Humanoid") and target.Humanoid.RigType or Enum.HumanoidRigType.R6
    
            -- Function to map selected part based on RigType
            local function getMappedPart(partName)
                if rigType == Enum.HumanoidRigType.R15 then
                    local mapping = {
                        ["Torso"] = "UpperTorso",
                        ["Head"] = "Head",
                        ["Left Arm"] = "LeftUpperArm",
                        ["Right Arm"] = "RightUpperArm",
                        ["Left Leg"] = "LeftUpperLeg",
                        ["Right Leg"] = "RightUpperLeg",
                    }
                    return target:FindFirstChild(mapping[partName]) or target:FindFirstChild(partName)
                else -- R6
                    return target:FindFirstChild(partName)
                end
            end
    
            -- Get the specific part based on selection and RigType
            local targetPart = getMappedPart(SELECTED_PART)
    
            if targetPart then
                local targetPosition = targetPart.Position
                local direction = (targetPosition - humanoidRootPart.Position).Unit
                local currentCFrame = humanoidRootPart.CFrame
                local desiredCFrame = CFrame.lookAt(humanoidRootPart.Position, targetPosition)
    
                -- Smoothly interpolate the humanoid's CFrame towards the target
                humanoidRootPart.CFrame = currentCFrame:Lerp(desiredCFrame, ROTATION_SPEED)
            end
        end
    end
    
    -- Function to smoothly adjust the camera towards the target
    local function smoothCameraLock(target)
        if target and TRACKED_MODEL and TRACKED_MODEL:FindFirstChild("HumanoidRootPart") then
            local targetPart = TRACKED_MODEL:FindFirstChild(SELECTED_PART) or TRACKED_MODEL:FindFirstChild("HumanoidRootPart")
            if not targetPart then return end
    
            local targetCFrame = CFrame.new(
                targetPart.Position + (Camera.CFrame.LookVector * -10),  -- Offset the camera
                targetPart.Position
            )
    
            Camera.CFrame = Camera.CFrame:Lerp(targetCFrame, CAMERA_LERP_SPEED)
        end
    end
    
    -- Function to handle key presses for lock-on and ShiftLock
    local function onInputBegan(input, gameProcessed)
        if gameProcessed then return end
    
        if input.KeyCode == LOCK_KEY then
            if SHIFTLOCK_ACTIVE then return end  -- Prevent lock-on if ShiftLock is active
            if TRACKED_MODEL then
                -- If already tracking a target, deselect it
                toggleTarget(TRACKED_MODEL, SELECTED_PART)
            else
                -- Find and select the nearest humanoid
                local nearest = findNearestHumanoid()
                if nearest then
                    toggleTarget(nearest, SELECTED_PART)
                else
                    -- Optional: Notify the player that no target was found
                    -- Example Notification:
                    -- player:FindFirstChildOfClass("PlayerGui"):SetCore("SendNotification", {
                    --     Title = "Lock-On",
                    --     Text = "No targets nearby!",
                    --     Duration = 2
                    -- })
                end
            end
        elseif input.KeyCode == SHIFT_KEY then
            -- Activate ShiftLock
            if TRACKED_MODEL then
                SHIFTLOCK_ACTIVE = true
                -- Optionally disable user control during ShiftLock
                GuiService.SelectedObject = nil  -- Deselect any UI elements
            end
        end
    end
    
    local function onInputEnded(input, gameProcessed)
        if input.KeyCode == SHIFT_KEY then
            -- Deactivate ShiftLock
            if SHIFTLOCK_ACTIVE then
                SHIFTLOCK_ACTIVE = false
            end
        end
    end
    
    -- Listen for key presses
    UserInputService.InputBegan:Connect(onInputBegan)
    UserInputService.InputEnded:Connect(onInputEnded)
    
    -- Create the GUI
    createLockOnGUI()
    
    -- Ensure the script continues working when the character respawns
    player.CharacterAdded:Connect(function(newCharacter)
        character = newCharacter
        humanoidRootPart = newCharacter:WaitForChild("HumanoidRootPart")
    
        -- Clean up any existing ESP when the character respawns
        if ESP_BILLBOARD then
            ESP_BILLBOARD:Destroy()
            ESP_BILLBOARD = nil
        end
        TRACKED_MODEL = nil
    end)
    
    -- RunService to update the face tracking smoothly
    RunService.Heartbeat:Connect(function()
        if TRACKED_MODEL then
            smoothFaceTarget(TRACKED_MODEL)
            if SHIFTLOCK_ACTIVE then
                smoothCameraLock(TRACKED_MODEL)
            end
        end
    end)
    
    -- Optional: Reset camera when ShiftLock is deactivated
    RunService.RenderStepped:Connect(function()
        if not SHIFTLOCK_ACTIVE and TRACKED_MODEL then
            -- You can implement camera reset or smooth transition here if needed
        end
    end)
    

    Explanation of Enhancements

    1. Super-Tracking Enhancements:

      • Heartbeat Connection: Switched the update loop to use RunService.Heartbeat instead of RunService.RenderStepped. Heartbeat runs after the physics simulation, providing a more consistent update rate which is better for smooth tracking.
      • Reduced Rotation Speed: Lowered ROTATION_SPEED to 0.1 for finer interpolation, making the rotation towards the target smoother and less abrupt.
      • Camera Interpolation: Introduced smoothCameraLock function that smoothly interpolates the camera's CFrame towards the target. This ensures that the camera movement is fluid without noticeable stutters.
      • Increased Max Lock Distance: Increased MAX_LOCK_DISTANCE to 25 studs, allowing players to lock on to targets that are further away, enhancing gameplay experience.
    2. ShiftLock Support:

      • Shift Key Detection: Added listeners for InputBegan and InputEnded to detect when the Shift key (LEFT_SHIFT) is pressed and released.
      • ShiftLock State: Introduced SHIFTLOCK_ACTIVE variable to track whether ShiftLock is active.
      • Camera Locking: When ShiftLock is active, the smoothCameraLock function continuously updates the camera to follow the target smoothly. Releasing the Shift key deactivates ShiftLock, returning control to the player.
      • Interaction Prevention: When ShiftLock is active, the LOCK_KEY (E) is temporarily disabled to prevent conflicting behaviors.
    3. Additional Improvements:

      • Target Validation: Enhanced the findNearestHumanoid function to ensure that only alive players (Humanoid.Health > 0) are considered as valid targets.
      • Responsive GUI: The GUI now updates the selected part in real-time, and hovering effects have been refined for better user experience.
      • ESP Cleanup on Respawn: Ensured that any existing ESP indicators are removed when the player respawns to prevent visual clutter or inaccuracies.

    Usage Instructions

    1. Lock-On to Target:

      • Press the E key to lock on to the nearest target within the specified distance.
      • Press the E key again to deselect the current target.
    2. ShiftLock Mode:

      • Press and hold the Shift key to activate ShiftLock mode, which locks the camera to the selected target.
      • Release the Shift key to deactivate ShiftLock and regain normal camera control.
    3. Selecting Target Parts:

      • Use the GUI on the left side of the screen to select which part of the target you want to lock onto (e.g., Head, Torso).
      • The ESP indicator will update to highlight the selected part.

    Notes

    • Camera Control: This script overrides the default camera when ShiftLock is active. Ensure that no other scripts conflict with camera manipulation to maintain smooth behavior.

    • Performance Considerations: Although the script is optimized for smooth tracking, excessive use or tracking multiple targets simultaneously may impact performance on lower-end devices.

    • Security: Ensure that this script is placed in a LocalScript, as it manipulates client-side camera and UI elements. Server-side scripts cannot control individual player cameras.

    Feel free to adjust the configuration parameters (ROTATION_SPEED, Câmara_LERP_SPEED, MAX_LOCK_DISTANCE, etc.) to better fit your game's specific needs and desired responsiveness.