Further enhance and add in a more advanced state blocking with game-state unblock and a more advanced flicker block.

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

-- Remotes
local BlockRemote = ReplicatedStorage:WaitForChild("LightsaberRemotes"):WaitForChild("Block")
local UnblockRemote = ReplicatedStorage:WaitForChild("LightsaberRemotes"):WaitForChild("Unblock")
local UpdateBlockDirectionRemote = ReplicatedStorage:WaitForChild("LightsaberRemotes"):WaitForChild("UpdateBlockDirection")

-- Settings
local autoBlockEnabled = true
local blockDistance = 20
local autoBlockReactionTime = 0.1
local autoBlockDuration = 0.5
local autoBlockCooldown = 0.2
local lastBlockTime = 0

-- State blocking variables
local blockState = "Idle"
local blockDirection = Vector3.new(0, 0, 0)

-- Flicker block variables
local flickerBlockEnabled = true
local flickerBlockThreshold = 0.1
local flickerBlockCooldown = 0.1
local lastFlickerBlockTime = 0

-- Local player and character
local localPlayer = Players.LocalPlayer
local localCharacter = localPlayer.Character

-- Function to update block direction
local function updateBlockDirection(direction)
    if direction then
        blockDirection = direction
        UpdateBlockDirectionRemote:FireServer(blockDirection)
    end
end

-- Function to block
local function block()
    if autoBlockEnabled and tick() - lastBlockTime >= autoBlockCooldown then
        BlockRemote:FireServer()
        lastBlockTime = tick()
    end
end

-- Function to unblock
local function unblock()
    UnblockRemote:FireServer()
end

-- Function to handle state blocking
local function handleStateBlocking(player)
    local humanoid = player.Character:FindFirstChild("Humanoid")
    if humanoid then
        local humanoidRootPart = humanoid.RootPart
        if humanoidRootPart then
            local localPosition = localCharacter.PrimaryPart.Position
            local playerPosition = humanoidRootPart.Position
            local distance = (playerPosition - localPosition).Magnitude

            if distance <= blockDistance then
                -- Calculate block direction
                local direction = (playerPosition - localPosition).Unit
                updateBlockDirection(direction)

                -- State blocking
                if blockState == "Idle" then
                    block()
                    blockState = "Blocking"
                elseif blockState == "Blocking" then
                    if distance < blockDistance / 2 then
                        unblock()
                        blockState = "Idle"
                    end
                end
            else
                unblock()
                blockState = "Idle"
            end
        end
    end
end

-- Function to handle flicker block
local function handleFlickerBlock(player)
    local humanoid = player.Character:FindFirstChild("Humanoid")
    if humanoid then
        local humanoidRootPart = humanoid.RootPart
        if humanoidRootPart then
            local localPosition = localCharacter.PrimaryPart.Position
            local playerPosition = humanoidRootPart.Position
            local distance = (playerPosition - localPosition).Magnitude

            if distance <= blockDistance and tick() - lastFlickerBlockTime >= flickerBlockCooldown then
                -- Calculate block direction
                local direction = (playerPosition - localPosition).Unit
                updateBlockDirection(direction)

                -- Flicker block
                block()
                task.wait(flickerBlockThreshold)
                unblock()
                lastFlickerBlockTime = tick()
            end
        end
    end
end

-- Main loop
RunService.RenderStepped:Connect(function()
    local closestPlayer = nil
    local shortestDistance = math.huge

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

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

    if closestPlayer then
        if flickerBlockEnabled then
            handleFlickerBlock(closestPlayer)
        else
            handleStateBlocking(closestPlayer)
        end
    end
end)