Further enhance and fix any error and parsing error's:

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

local LocalPlayer = Players.LocalPlayer
local Mouse = LocalPlayer:GetMouse()

-- Configuration
local HALF_SWING_DELAY = 0.15  -- Adjust this value for optimal timing
local SWING_COOLDOWN = 0.1  -- Cooldown between swings
local MAX_DISTANCE = 15  -- Maximum distance to target player

-- Advanced swing states
local SwingStates = {
    IDLE = 0,
    WINDUP = 1,
    SWING = 2,
    FOLLOW_THROUGH = 3,
    RECOVERY = 4
}

local currentSwingState = SwingStates.IDLE
local lastSwingTime = 0
local targetPlayer = nil

-- Function to perform a single swing
local function performSwing()
    local currentTime = tick()
    if currentTime - lastSwingTime >= SWING_COOLDOWN then
        mouse1click()
        lastSwingTime = currentTime
    end
end

-- Advanced half-swing function
local function advancedHalfSwing()
    if currentSwingState ~= SwingStates.IDLE then return end
    
    currentSwingState = SwingStates.WINDUP
    performSwing()
    
    task.delay(HALF_SWING_DELAY, function()
        if currentSwingState == SwingStates.WINDUP then
            currentSwingState = SwingStates.SWING
            performSwing()
            
            task.delay(HALF_SWING_DELAY / 2, function()
                currentSwingState = SwingStates.FOLLOW_THROUGH
                
                task.delay(HALF_SWING_DELAY / 2, function()
                    currentSwingState = SwingStates.RECOVERY
                    
                    task.delay(SWING_COOLDOWN, function()
                        currentSwingState = SwingStates.IDLE
                    end)
                end)
            end)
        end
    end)
end

-- Function to get the closest player
local function getClosestPlayer()
    local closestPlayer = nil
    local shortestDistance = math.huge
    local localCharacter = LocalPlayer.Character

    if localCharacter and localCharacter:FindFirstChild("HumanoidRootPart") then
        local localPosition = localCharacter.HumanoidRootPart.Position

        for _, player in ipairs(Players:GetPlayers()) do
            if player ~= LocalPlayer and player.Character and player.Character:FindFirstChild("HumanoidRootPart") then
                local playerPosition = player.Character.HumanoidRootPart.Position
                local distance = (playerPosition - localPosition).Magnitude

                if distance < shortestDistance and distance <= MAX_DISTANCE then
                    closestPlayer = player
                    shortestDistance = distance
                end
            end
        end
    end

    return closestPlayer
end

-- Main loop
RunService.Heartbeat:Connect(function()
    targetPlayer = getClosestPlayer()
    
    if targetPlayer and UserInputService:IsKeyDown(Enum.KeyCode.E) then
        advancedHalfSwing()
    end
end)

-- Hook into animation events for more precise timing
LocalPlayer.Character.ChildAdded:Connect(function(child)
    if child:IsA("Humanoid") then
        child.AnimationPlayed:Connect(function(animTrack)
            if animTrack.Animation.AnimationId:match("12625839385") then  -- RightSwing animation ID
                task.spawn(function()
                    task.wait(animTrack.Length * 0.5)  -- Wait for half of the animation duration
                    advancedHalfSwing()
                end)
            end
        end)
    end
end)

-- Function to predict enemy movements
local function predictEnemy Movement()
    if targetPlayer and targetPlayer.Character then
        local enemyPosition = targetPlayer.Character.HumanoidRootPart.Position
        local enemyVelocity = targetPlayer.Character.HumanoidRootPart.Velocity
        
        -- Calculate predicted position
        local predictedPosition = enemyPosition + enemyVelocity * 0.1
        
        -- Adjust swing timing based on predicted position
        if (predictedPosition - LocalPlayer.Character.HumanoidRootPart.Position).Magnitude <= MAX_DISTANCE then
            advancedHalfSwing()
        end
    end
end

-- Run prediction function every 0.1 seconds
RunService.Heartbeat:Connect(function()
    predictEnemyMovement()
end)