Make it keep the humanoidrootpart and make it stay intact while still tracking other player. (Make it track based-off the direction they're facing).

```
-- 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 ReplicatedStorage = game:GetService("ReplicatedStorage")

-- Configuration
local ROTATION_SPEED = 1.1  -- Adjusted for smoother and faster rotation (0 < speed <=1)
local LOCK_KEY = Enum.KeyCode.E  -- Key to press for lock-on
local MAX_LOCK_DISTANCE = 30  -- Increased maximum distance to allow selecting farther targets
local TARGET_UPDATE_RATE = 0.1 -- Time in seconds between target updates to optimize performance

-- 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"}

-- Event System for Custom Scripts
local LockOnEvents = {
    OnTargetLocked = Instance.new("BindableEvent"),
    OnTargetUnlocked = Instance.new("BindableEvent"),
}

-- Function to create RemoteEvents for server-client communication
local function setupRemoteEvents()
    -- Create RemoteEvents if they don't exist
    if not ReplicatedStorage:FindFirstChild("LockOnRemoteEvents") then
        local remoteFolder = Instance.new("Folder")
        remoteFolder.Name = "LockOnRemoteEvents"
        remoteFolder.Parent = ReplicatedStorage

        local remoteLockOn = Instance.new("RemoteEvent")
        remoteLockOn.Name = "TargetLocked"
        remoteLockOn.Parent = remoteFolder

        local remoteUnlock = Instance.new("RemoteEvent")
        remoteUnlock.Name = "TargetUnlocked"
        remoteUnlock.Parent = remoteFolder
    end
end

setupRemoteEvents()

local RemoteEvents = ReplicatedStorage.LockOnRemoteEvents

-- 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
        -- Fire OnTargetUnlocked event
        LockOnEvents.OnTargetUnlocked:Fire(target)
        -- Trigger RemoteEvent for unlocking
        RemoteEvents.TargetUnlocked:FireServer(target)
    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")

            -- Fire OnTargetLocked event
            LockOnEvents.OnTargetLocked:Fire(target)
            -- Trigger RemoteEvent for locking
            RemoteEvents.TargetLocked:FireServer(target)
        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 with caching
local lastSearchTime = 0
local function findNearestHumanoid()
    local currentTime = tick()
    if currentTime - lastSearchTime < TARGET_UPDATE_RATE then
        return nil  -- Skip search to optimize performance
    end
    lastSearchTime = currentTime

    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 = targetPart.Position
            local direction = (targetPosition - humanoidRootPart.Position).Unit
            local targetCFrame = CFrame.lookAt(humanoidRootPart.Position, humanoidRootPart.Position + direction)

            -- 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)

-- Expose the event system for custom scripts
return {
    LockOnEvents = LockOnEvents
}