Fix this script, and further optimize:

```
-- 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 = 1.1          -- Smoother interpolation for character rotation
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 = 30         -- Maximum distance to search for targets
local CAMERA_LERP_SPEED = 0.15      -- Camera interpolation speed
local MIN_ZOOM = 5                   -- Minimum camera zoom distance
local MAX_ZOOM = 20                  -- Maximum camera zoom distance
local ZOOM_SPEED = 1.5               -- Speed of zooming

-- Player and Character
local player = Players.LocalPlayer
local character = player.Character or player.CharacterAdded:Wait()
local humanoidRootPart = character:WaitForChild("HumanoidRootPart")

-- Camera Variables
local originalCameraCFrame = Camera.CFrame -- Store the original camera CFrame
local cameraOffset = Vector3.new(0, 2, -10) -- Default camera offset
local currentZoom = cameraOffset.Z
local isCameraResetting = false           -- Flag to prevent multiple reset operations

-- Tracking 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()
    -- Check if GUI already exists to prevent duplicates
    if player.PlayerGui:FindFirstChild("LockOnGUI") then return end

    -- 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
        -- Reset camera if ShiftLock was active
        if SHIFTLOCK_ACTIVE then
            SHIFTLOCK_ACTIVE = false
            isCameraResetting = true
            resetCamera()
        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 and targetPart:IsA("BasePart") 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 or isn't a BasePart
            TRACKED_MODEL = nil
            -- Optional: Add a notification here
        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 and targetPart:IsA("BasePart") 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 or not targetPart:IsA("BasePart") then return end

            -- Calculate desired camera position based on target
            local desiredPosition = targetPart.Position + (targetPart.CFrame:VectorToWorldSpace(cameraOffset))
            local desiredLookAt = targetPart.Position

            -- Smoothly interpolate the camera's CFrame towards the target
            Camera.CFrame = Camera.CFrame:Lerp(CFrame.new(desiredPosition, desiredLookAt), CAMERA_LERP_SPEED)
        end
    end

    -- Function to reset the camera to its original state
    local function resetCamera()
        if isCameraResetting then return end  -- Prevent multiple simultaneous resets
        isCameraResetting = true

        -- Smoothly interpolate the camera back to its original CFrame
        local tweenInfo = TweenInfo.new(0.5, Enum.EasingStyle.Quad, Enum.EasingDirection.Out)
        local tween = TweenService:Create(Camera, tweenInfo, {CFrame = originalCameraCFrame})
        tween:Play()

        tween.Completed:Connect(function()
            isCameraResetting = false
            cameraOffset = Vector3.new(0, 2, -10) -- Reset to default offset
            currentZoom = cameraOffset.Z
        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
            if TRACKED_MODEL then
                SHIFTLOCK_ACTIVE = true
                -- Optionally disable user control during ShiftLock
                GuiService.SelectedObject = nil  -- Deselect any UI elements
                originalCameraCFrame = Camera.CFrame  -- Update original camera position
                Camera.CameraType = Enum.CameraType.Scriptable -- Override default camera
            end
        elseif SHIFTLOCK_ACTIVE then
            -- Handle Zoom In/Out while ShiftLock is active
            if input.KeyCode == Enum.KeyCode.Q then
                currentZoom = math.clamp(currentZoom - ZOOM_SPEED, MIN_ZOOM, MAX_ZOOM)
                cameraOffset = Vector3.new(cameraOffset.X, cameraOffset.Y, currentZoom)
            elseif input.KeyCode == Enum.KeyCode.X then
                currentZoom = math.clamp(currentZoom + ZOOM_SPEED, MIN_ZOOM, MAX_ZOOM)
                cameraOffset = Vector3.new(cameraOffset.X, cameraOffset.Y, currentZoom)
            end
        end
    end

    local function onInputEnded(input, gameProcessed)
        if input.KeyCode == SHIFT_KEY then
            -- Deactivate ShiftLock
            if SHIFTLOCK_ACTIVE then
                SHIFTLOCK_ACTIVE = false
                Camera.CameraType = Enum.CameraType.Custom -- Restore default camera
                resetCamera()
            end
        end
    end

    -- Listen for key presses
    UserInputService.InputBegan:Connect(onInputBegan)
    UserInputService.InputEnded:Connect(onInputEnded)

    -- Create the GUI
    createLockOnGUI()

    -- Function to handle character respawn
    local function onCharacterAdded(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
        SHIFTLOCK_ACTIVE = false
        resetCamera()  -- Reset camera on respawn
    end

    player.CharacterAdded:Connect(onCharacterAdded)

    -- RunService to update the face tracking and camera smoothly
    RunService.Heartbeat:Connect(function()
        if TRACKED_MODEL then
            smoothFaceTarget(TRACKED_MODEL)
            if SHIFTLOCK_ACTIVE then
                smoothCameraLock(TRACKED_MODEL)
            end
        end
    end)
end