Improve and extend this roblox auto-block script, and add a lot of handler, make it based-off the remotes.

```
Remotes: game:GetService("ReplicatedStorage").LightsaberRemotes.Block
Remotes: game:GetService("ReplicatedStorage").LightsaberRemotes.Unblock
Remotes: game:GetService("ReplicatedStorage").LightsaberRemotes.UpdateManualBlock
Remotes: game:GetService("ReplicatedStorage").LightsaberRemotes.UpdateBlockDirection
```

These links are reference links:

https://raw.githubusercontent.com/Synarcy/SaberShowdown/refs/heads/main/AutoBlockSS.lua

Enhance this lua script:

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

local player = Players.LocalPlayer
local character = player.Character or player.CharacterAdded:Wait()
local humanoid = character:WaitForChild("Humanoid")

local LightsaberRemotes = ReplicatedStorage:WaitForChild("LightsaberRemotes")
local BlockRemote = LightsaberRemotes:WaitForChild("Block")
local BlockSlapRemote = LightsaberRemotes:WaitForChild("BlockSlap")
local UnblockRemote = LightsaberRemotes:WaitForChild("Unblock")
local UpdateManualBlockRemote = LightsaberRemotes:WaitForChild("UpdateManualBlock")
local UpdateBlockDirectionRemote = LightsaberRemotes:WaitForChild("UpdateBlockDirection")

local isAutoBlockEnabled = false
local isBlocking = false
local lastBlockTime = 0
local blockCooldown = 0.1
local slapCooldown = 3
local lastSlapTime = 0

local blockDirections = {
    [1] = Vector3.new(0, 0, -1),  -- Front
    [2] = Vector3.new(1, 0, 0),   -- Right
    [3] = Vector3.new(0, 0, 1),   -- Back
    [4] = Vector3.new(-1, 0, 0),  -- Left
    [5] = Vector3.new(0, 1, 0),   -- Up
    [6] = Vector3.new(0, -1, 0)   -- Down
}

local animationIds = {
    ["RightSwing"] = 12625839385,
    ["OverheadSwing"] = 12625841878,
    ["LeftSwing"] = 12625843823,
    ["BackLeftSwing"] = 12625846167,
    ["FrontRightSwing"] = 12625848489,
    ["BackRightSwing"] = 12625851115,
    ["FrontLeftSwing"] = 12625853257,
    ["Slap"] = 12625891544,
    ["Aerial"] = 12625908201
}

local function getClosestEnemy()
    local closestDistance = math.huge
    local closestEnemy = nil
    local myPosition = character.PrimaryPart.Position

    for _, otherPlayer in pairs(Players:GetPlayers()) do
        if otherPlayer ~= player and otherPlayer.Character and otherPlayer.Character:FindFirstChild("HumanoidRootPart") then
            local distance = (otherPlayer.Character.HumanoidRootPart.Position - myPosition).Magnitude
            if distance < closestDistance then
                closestDistance = distance
                closestEnemy = otherPlayer
            end
        end
    end

    return closestEnemy, closestDistance
end

local function getBlockDirection(enemyPosition)
    local relativePosition = enemyPosition - character.PrimaryPart.Position
    local angle = math.atan2(relativePosition.X, relativePosition.Z)
    local direction = math.floor(((angle + math.pi) / (math.pi * 2) * 4 + 0.5) % 4) + 1
    return direction
end

local function startBlocking(direction)
    if not isBlocking and tick() - lastBlockTime > blockCooldown then
        isBlocking = true
        lastBlockTime = tick()
        BlockRemote:FireServer()
        UpdateBlockDirectionRemote:FireServer(direction)
        UpdateManualBlockRemote:FireServer(blockDirections[direction])
    end
end

local function stopBlocking()
    if isBlocking then
        isBlocking = false
        UnblockRemote:FireServer()
    end
end

local function autoCounter()
    local enemy, distance = getClosestEnemy()
    if enemy and distance < 10 and tick() - lastSlapTime > slapCooldown then
        BlockSlapRemote:FireServer()
        lastSlapTime = tick()
    end
end

local function onAnimationPlayed(animTrack)
    local enemy, distance = getClosestEnemy()
    if not enemy or distance > 20 then return end

    for animName, animId in pairs(animationIds) do
        if animTrack.Animation.AnimationId == "rbxassetid://" .. animId then
            local blockDirection = getBlockDirection(enemy.Character.PrimaryPart.Position)
            
            if animName:find("Swing") or animName == "Slap" then
                startBlocking(blockDirection)
                task.wait(animTrack.Length)
                stopBlocking()
            elseif animName == "Aerial" then
                task.wait(0.2)  -- Wait for the enemy to be in air
                startBlocking(5)  -- Block upwards
                task.wait(0.5)
                stopBlocking()
            end
            
            break
        end
    end
end

local function setupAutoBlock()
    for _, otherPlayer in pairs(Players:GetPlayers()) do
        if otherPlayer ~= player then
            otherPlayer.CharacterAdded:Connect(function(char)
                local humanoid = char:WaitForChild("Humanoid")
                humanoid.AnimationPlayed:Connect(onAnimationPlayed)
            end)
            if otherPlayer.Character then
                local humanoid = otherPlayer.Character:FindFirstChild("Humanoid")
                if humanoid then
                    humanoid.AnimationPlayed:Connect(onAnimationPlayed)
                end
            end
        end
    end

    Players.PlayerAdded:Connect(function(newPlayer)
        newPlayer.CharacterAdded:Connect(function(char)
            local humanoid = char:WaitForChild("Humanoid")
            humanoid.AnimationPlayed:Connect(onAnimationPlayed)
        end)
    end)
end

local function toggleAutoBlock()
    isAutoBlockEnabled = not isAutoBlockEnabled
    if isAutoBlockEnabled then
        print("Auto Block enabled")
        setupAutoBlock()
    else
        print("Auto Block disabled")
        stopBlocking()
    end
end

UserInputService.InputBegan:Connect(function(input, gameProcessed)
    if not gameProcessed and input.KeyCode == Enum.KeyCode.X then
        toggleAutoBlock()
    end
end)

RunService.Heartbeat:Connect(function()
    if isAutoBlockEnabled then
        autoCounter()
    end
end)

print("Advanced Auto Block script loaded. Press X to toggle.")
```