Further enhance:

```
-- Services
local Players = game:GetService("Players")
local RunService = game:GetService("RunService")
local plr = Players.LocalPlayer

-- Configuration Settings
local Settings = {
    Autoparry = {
        Toggle = true,
        Range = 25,
        Delay = 0.05, -- Reduced base delay for faster reactions
        Fov = 180,
        Facing = true,
        Dodgerange = 3,
        Aimhelper = true,
    },
    ESP = {
        Toggle = false,
        Config = {}
    },
    Tpaura = {
        Toggle = false,
    },
}

-- Ping Adjustment Settings
local PingSettings = {
    AdjustmentFactor = 0.001, -- Seconds added per ms ping
    MinimumDelay = 0.05, -- Minimum possible delay in seconds
    MaximumDelay = 0.3, -- Maximum possible delay in seconds
}

-- Animation Timings
local anims = {
    -- Saitama
    ["rbxassetid://10469493270"] = {0, 0.30},
    ["rbxassetid://10469630950"] = {0, 0.30},
    ["rbxassetid://10469639222"] = {0, 0.30},
    ["rbxassetid://10469643643"] = {0, 0.30},
    -- Hunter
    ["rbxassetid://13532562418"] = {0, 0.30},
    ["rbxassetid://13532600125"] = {0, 0.30},
    ["rbxassetid://13532604085"] = {0, 0.30},
    ["rbxassetid://13294471966"] = {0, 0.30},
    -- Cyborg
    ["rbxassetid://13491635433"] = {0, 0.30},
    ["rbxassetid://13296577783"] = {0, 0.30},
    ["rbxassetid://13295919399"] = {0, 0.30},
    ["rbxassetid://13295936866"] = {0, 0.30},
    -- Ninja
    ["rbxassetid://13370310513"] = {0, 0.30},
    ["rbxassetid://13390230973"] = {0, 0.30},
    ["rbxassetid://13378751717"] = {0, 0.30},
    ["rbxassetid://13378708199"] = {0, 0.30},
    abilities = {}
}

-- Dodge Animations Timing
local dodges = {
    ["rbxassetid://10479335397"] = {0, 0.50}, 
    ["rbxassetid://13380255751"] = {0, 0.50},
    ["rbxassetid://10480796021"] = {0, 0.50},
    ["rbxassetid://10480793962"] = {0, 0.50}
}

-- Barrage Animations Timing
local barrages = {
    ["rbxassetid://10466974800"] = {0.20, 1.80},
    ["rbxassetid://12534735382"] = {0.20, 1.80}
}

-- Abilities Timing
local abilities = {
    ["rbxassetid://10468665991"] = {0.15, 0.60},
    ["rbxassetid://13376869471"] = {0.05, 1},
    ["rbxassetid://13376962659"] = {0, 2},
    ["rbxassetid://12296882427"] = {0.05, 1}, -- Sonic
    ["rbxassetid://13309500827"] = {0.05, 1}, -- Sonic
    ["rbxassetid://13365849295"] = {0, 1}, -- Sonic
    ["rbxassetid://13377153603"] = {0, 1}, -- Sonic
    ["rbxassetid://12509505723"] = {0.09, 2}, -- Dash for Cyborg
}

-- Action Durations
local durations = {
    anim = 0.3,
    dodge = 0.9,
    barrage = 0.9,
    ability = 0.6,
}

-- Prediction Constants
local VELOCITY_ALPHA = 0.2 -- EMA smoothing factor
local PREDICTION_TIME_BASE = 0.2
local PREDICTION_TIME_ADJUSTMENT_FACTOR = 0.02
local ROTATION_SPEED = 25 -- Adjust as needed

-- Variables for EMA
local velocityEMA = Vector3.new(0, 0, 0)

-- Cooldowns
local isParrying = false
local isBlocking = false

-- Cached Closest Players
local closestplr, anim, plrDirection, unit, value, dodge, ability, barrage

-- Helper Function for Debug Logging (Optional)
local function debugLog(msg)
    -- Uncomment the line below to enable debug logging
    -- print("[DEBUG]", msg)
end

-- Function to Find Closest Players Within Range
local function closest()
    closestplr = {}
    if not plr.Character or not plr.Character:FindFirstChild("HumanoidRootPart") then
        return closestplr
    end
    
    for _, v in ipairs(Players:GetPlayers()) do
        if v ~= plr and v.Character and v.Character:FindFirstChild("HumanoidRootPart") then
            local dist = (v.Character.HumanoidRootPart.Position - plr.Character.HumanoidRootPart.Position).Magnitude
            if dist < Settings.Autoparry.Range then
                table.insert(closestplr, v)
            end
        end
    end
    return closestplr
end

-- Advanced EMA-Based Position Prediction Function
local function getPredictedPosition(targetCharacter)
    local torsoPartName = "HumanoidRootPart"
    local humanoidRootPart = plr.Character.HumanoidRootPart
    local targetTorso = targetCharacter:FindFirstChild(torsoPartName)
    if not targetTorso then
        debugLog("Target does not have " .. torsoPartName .. ".")
        return nil
    end

    -- Get current velocity
    local currentVelocity = targetTorso.Velocity

    -- Update Exponential Moving Average (EMA) for velocity
    velocityEMA = (currentVelocity * VELOCITY_ALPHA) + (velocityEMA * (1 - VELOCITY_ALPHA))

    -- Calculate dynamic prediction time based on velocity magnitude and distance
    local distance = (targetTorso.Position - humanoidRootPart.Position).Magnitude
    local velocityMagnitude = velocityEMA.Magnitude

    -- Prevent division by zero and unrealistic prediction
    velocityMagnitude = velocityMagnitude > 0 and velocityMagnitude or 0.1

    -- Optimal prediction time (e.g., time to reach the player)
    local predictionTime = PREDICTION_TIME_BASE + (velocityMagnitude * PREDICTION_TIME_ADJUSTMENT_FACTOR) + (distance * PREDICTION_TIME_ADJUSTMENT_FACTOR)
    predictionTime = math.clamp(predictionTime, 0.2, 0.8) -- Clamp prediction time between 0.2 and 0.8 seconds

    -- Calculate predicted position
    local futurePosition = targetTorso.Position + (velocityEMA * predictionTime)
    debugLog(string.format("Predicted position: (%.2f, %.2f, %.2f); Prediction Time: %.2f", 
        futurePosition.X, futurePosition.Y, futurePosition.Z, predictionTime))
    
    return futurePosition
end

-- Function: Instantly Rotate to Face the Predicted Target Position
local function instantRotateToPosition(targetPosition)
    if not targetPosition or not plr.Character or not plr.Character:FindFirstChild("HumanoidRootPart") then return end

    local humanoidRootPart = plr.Character.HumanoidRootPart
    local desiredCFrame = CFrame.new(humanoidRootPart.Position, targetPosition)
    humanoidRootPart.CFrame = desiredCFrame
    debugLog("Instantly rotated to face predicted position.")
end

-- Function: Smoothly Rotate to Face the Predicted Target Position
local function smoothRotateToPosition(targetPosition, deltaTime)
    if not targetPosition or not plr.Character or not plr.Character:FindFirstChild("HumanoidRootPart") then return end

    local humanoidRootPart = plr.Character.HumanoidRootPart
    local direction = (Vector3.new(targetPosition.X, humanoidRootPart.Position.Y, targetPosition.Z) - humanoidRootPart.Position).Unit
    local desiredCFrame = CFrame.new(humanoidRootPart.Position, humanoidRootPart.Position + direction)

    -- Smoothly interpolate the CFrame
    humanoidRootPart.CFrame = humanoidRootPart.CFrame:Lerp(desiredCFrame, ROTATION_SPEED * deltaTime)
    debugLog("Smoothly rotated to face predicted position.")
end

-- Function to Predict Future Position Based on Target's Velocity using EMA
local function predictPosition(enemy, deltaTime)
    return getPredictedPosition(enemy.Character)
end

-- Function to Check if Player is Currently Performing an Attack
local function attackchecker()
    if not plr.Character or not plr.Character:FindFirstChild("Humanoid") then
        return false
    end
    
    for _, Anim in ipairs(plr.Character.Humanoid.Animator:GetPlayingAnimationTracks()) do
        if anims[Anim.Animation.AnimationId] or dodges[Anim.Animation.AnimationId] or abilities[Anim.Animation.AnimationId] or barrages[Anim.Animation.AnimationId] then
            return true
        end
    end
    return false
end

-- Function to Determine if Enemy is Facing the Player
local function isfacing(enemy)
    if Settings.Autoparry.Toggle then
        if Settings.Autoparry.Facing then
            if not plr.Character:FindFirstChild("Head") or not enemy.Character:FindFirstChild("Head") then
                return false
            end

            plrDirection = plr.Character.Head.CFrame.LookVector
            unit = (enemy.Character.Head.CFrame.Position - plr.Character.Head.CFrame.Position).Unit
            value = math.pow((plrDirection - unit).Magnitude / 2, 2)
            return value < Settings.Autoparry.Fov / 360
        else
            return true
        end
    end
    return false
end 

-- Function to Determine if Parry or Block is Allowed
local function allowed(enemy)
    if not plr.Character:FindFirstChild("M1ing") and not attackchecker() and isfacing(enemy) then 
        return true
    end
    return false
end

-- Function to Retrieve Current Ping in Seconds
local function getPing()
    local ping = plr:GetNetworkPing()
    -- Assuming GetNetworkPing() returns ping in milliseconds
    return ping / 1000
end

-- Function to Compute Adjusted Delay Based on Ping
local function computeAdjustedDelay(baseDelay)
    local ping = getPing()
    local adjustedDelay = baseDelay + (ping * PingSettings.AdjustmentFactor)
    -- Clamp the adjusted delay between minimum and maximum values
    adjustedDelay = math.clamp(adjustedDelay, PingSettings.MinimumDelay, PingSettings.MaximumDelay)
    return adjustedDelay
end

-- Parry Action Handler with Dynamic Delay
local function def(action)
    if isParrying or isBlocking then return end
    isParrying = true
    local adjustedDelay = computeAdjustedDelay(Settings.Autoparry.Delay)
    task.delay(adjustedDelay, function()
        print("Parry attempt | Action: " .. action)
        plr.Character.Communicate:FireServer({["Goal"] = "KeyPress", ["Key"] = Enum.KeyCode.F})
        local actionDuration = durations[action] or 0.3
        local adjustedDuration = computeAdjustedDelay(actionDuration)
        task.delay(adjustedDuration, function()
            plr.Character.Communicate:FireServer({["Goal"] = "KeyRelease", ["Key"] = Enum.KeyCode.F})
            isParrying = false
        end)
    end)
end

-- Block Action Handler with Dynamic Duration
local function block(action, duration)
    if isBlocking then return end
    isBlocking = true
    print("Block attempt | Action: " .. action)
    plr.Character.Communicate:FireServer({["Goal"] = "KeyPress", ["Key"] = Enum.KeyCode.B}) -- Assuming 'B' is the block key
    local blockDuration = duration or 0.5
    local adjustedBlockDuration = computeAdjustedDelay(blockDuration)
    task.delay(adjustedBlockDuration, function()
        plr.Character.Communicate:FireServer({["Goal"] = "KeyRelease", ["Key"] = Enum.KeyCode.B})
        isBlocking = false
    end)
end

-- Function to Rotate Player to Face the Predicted Position
local function rotateTowards(enemy, deltaTime)
    local predictedPos = predictPosition(enemy, deltaTime)
    if Settings.Autoparry.Aimhelper then
        -- Choose between instant or smooth rotation based on preference
        -- instantRotateToPosition(predictedPos)
        smoothRotateToPosition(predictedPos, deltaTime)
    end
end

-- Main Parry Function
local function parry(deltaTime)
    for _, c in ipairs(closest()) do
        if c and c.Character and c.Character:FindFirstChild("Humanoid") and c.Character.Humanoid:FindFirstChild("Animator") then
            rotateTowards(c, deltaTime)
            
            for _, v in ipairs(c.Character.Humanoid.Animator:GetPlayingAnimationTracks()) do
                anim = anims[v.Animation.AnimationId]
                dodge = dodges[v.Animation.AnimationId]
                ability = abilities[v.Animation.AnimationId]
                barrage = barrages[v.Animation.AnimationId]

                if allowed(c.Character) then
                    if anim and v.TimePosition >= anim[1] and v.TimePosition <= anim[2] then
                        task.spawn(function()
                            def("anim")
                        end)
                    elseif dodge and v.TimePosition > dodge[1] and v.TimePosition < dodge[2] then
                        task.spawn(function()
                            block("dodge", durations["dodge"])
                        end)
                    elseif barrage and v.TimePosition > barrage[1] and v.TimePosition < barrage[2] then
                        task.spawn(function()
                            def("barrage")
                        end)
                    elseif ability and v.TimePosition > ability[1] and v.TimePosition < ability[2] then
                        task.spawn(function()
                            def("ability")
                        end)
                    end
                end
            end
        end
    end
end

-- Connect Parry Function to Heartbeat for Real-Time Execution
RunService.Heartbeat:Connect(function(deltaTime)
    if Settings.Autoparry.Toggle then
        parry(deltaTime)
    end
end)

warn("Enhanced Autoparry and Auto-Block Script Executed with Dynamic Ping Handling")
```

Integrate it with this:

```
-- Services
local Players = game:GetService("Players")
local RunService = game:GetService("RunService")
local UserInputService = game:GetService("UserInputService")
local ReplicatedStorage = game:GetService("ReplicatedStorage")
local plr = Players.LocalPlayer

-- Advanced Configuration Settings
local Settings = {
    Autoparry = {
        Toggle = true,
        Range = 25,
        Delay = 0.05,
        Fov = 180,
        Facing = true,
        Dodgerange = 3,
        Aimhelper = true,
        PredictionMode = "Advanced", -- "Simple", "Advanced", "Neural"
        AutoAdjust = true,
        SuccessTracking = true
    },
    ESP = {
        Toggle = false,
        Config = {}
    },
    Tpaura = {
        Toggle = false,
    },
    Debug = {
        Enabled = false,
        VisualizePredict = false
    }
}

-- Enhanced Ping Management
local PingManager = {
    History = {},
    MaxHistorySize = 50,
    AdjustmentFactor = 0.001,
    MinDelay = 0.05,
    MaxDelay = 0.3,
    
    UpdatePing = function(self, newPing)
        table.insert(self.History, newPing)
        if #self.History > self.MaxHistorySize then
            table.remove(self.History, 1)
        end
    end,
    
    GetAveragePing = function(self)
        local sum = 0
        for _, ping in ipairs(self.History) do
            sum = sum + ping
        end
        return sum / #self.History
    end,
    
    GetPingVariance = function(self)
        local avg = self:GetAveragePing()
        local sumSquares = 0
        for _, ping in ipairs(self.History) do
            sumSquares = sumSquares + (ping - avg)^2
        end
        return math.sqrt(sumSquares / #self.History)
    end
}

-- Success Rate Tracking
local SuccessTracker = {
    Attempts = 0,
    Successes = 0,
    History = {},
    
    RecordAttempt = function(self, success)
        self.Attempts = self.Attempts + 1
        if success then
            self.Successes = self.Successes + 1
        end
        table.insert(self.History, {
            success = success,
            timestamp = tick(),
            ping = PingManager:GetAveragePing()
        })
    end,
    
    GetSuccessRate = function(self)
        return self.Successes / math.max(1, self.Attempts)
    end,
    
    AdjustTimings = function(self)
        local recentSuccess = self:GetRecentSuccessRate()
        if recentSuccess < 0.5 then
            Settings.Autoparry.Delay = math.min(Settings.Autoparry.Delay + 0.01, PingManager.MaxDelay)
        elseif recentSuccess > 0.8 then
            Settings.Autoparry.Delay = math.max(Settings.Autoparry.Delay - 0.01, PingManager.MinDelay)
        end
    end
}

-- Advanced Prediction System
local PredictionSystem = {
    LastPositions = {},
    LastVelocities = {},
    MaxHistory = 10,
    
    UpdateTarget = function(self, target, position)
        if not self.LastPositions[target] then
            self.LastPositions[target] = {}
            self.LastVelocities[target] = {}
        end
        
        table.insert(self.LastPositions[target], position)
        if #self.LastPositions[target] > 1 then
            local velocity = (self.LastPositions[target][#self.LastPositions[target]] - 
                            self.LastPositions[target][#self.LastPositions[target]-1]) / RunService.Heartbeat:Wait()
            table.insert(self.LastVelocities[target], velocity)
        end
        
        -- Maintain history size
        if #self.LastPositions[target] > self.MaxHistory then
            table.remove(self.LastPositions[target], 1)
            if #self.LastVelocities[target] > self.MaxHistory - 1 then
                table.remove(self.LastVelocities[target], 1)
            end
        end
    end,
    
    PredictPosition = function(self, target, timeAhead)
        if not self.LastPositions[target] or #self.LastPositions[target] < 2 then
            return target.Character and target.Character:FindFirstChild("HumanoidRootPart") and 
                   target.Character.HumanoidRootPart.Position
        end
        
        local currentPos = self.LastPositions[target][#self.LastPositions[target]]
        local averageVelocity = Vector3.new(0, 0, 0)
        for _, velocity in ipairs(self.LastVelocities[target]) do
            averageVelocity = averageVelocity + velocity
        end
        averageVelocity = averageVelocity / #self.LastVelocities[target]
        
        -- Apply acceleration prediction
        local acceleration = Vector3.new(0, 0, 0)
        if #self.LastVelocities[target] >= 2 then
            acceleration = (self.LastVelocities[target][#self.LastVelocities[target]] - 
                          self.LastVelocities[target][#self.LastVelocities[target]-1]) / RunService.Heartbeat:Wait()
        end
        
        return currentPos + (averageVelocity * timeAhead) + (0.5 * acceleration * timeAhead * timeAhead)
    end
}

-- Combat State Manager
local CombatState = {
    IsParrying = false,
    IsBlocking = false,
    LastActionTime = 0,
    ComboCounter = 0,
    
    StartParry = function(self)
        if self.IsParrying or self.IsBlocking then return false end
        self.IsParrying = true
        self.LastActionTime = tick()
        self.ComboCounter = self.ComboCounter + 1
        return true
    end,
    
    EndParry = function(self)
        self.IsParrying = false
        if tick() - self.LastActionTime > 2 then
            self.ComboCounter = 0
        end
    end
}

-- Animation Handler
local AnimationHandler = {
    Cache = {},
    
    CacheAnimation = function(self, animId)
        if not self.Cache[animId] then
            self.Cache[animId] = game:GetService("ContentProvider"):PreloadAsync({animId})
        end
    end,
    
    GetAnimationTiming = function(self, animTrack)
        local animId = animTrack.Animation.AnimationId
        -- Implementation of animation timing logic
        return anims[animId] or dodges[animId] or abilities[animId] or barrages[animId]
    end
}

-- Enhanced Main Parry Function with Advanced Prediction
local function enhancedParry(deltaTime)
    for _, target in ipairs(closest()) do
        if not target.Character or not target.Character:FindFirstChild("Humanoid") then continue end
        
        local predictedPos = PredictionSystem:PredictPosition(target, Settings.Autoparry.Delay)
        PredictionSystem:UpdateTarget(target, target.Character.HumanoidRootPart.Position)
        
        if Settings.Autoparry.AutoAdjust then
            SuccessTracker:AdjustTimings()
        end
        
        -- Rest of the parry logic remains the same as in your original code
        -- but now uses the enhanced prediction system and combat state manager
    end
end

-- Connect to RunService
RunService.Heartbeat:Connect(function(deltaTime)
    if Settings.Autoparry.Toggle then
        enhancedParry(deltaTime)
    end
    
    -- Update ping tracking
    PingManager:UpdatePing(plr:GetNetworkPing())
end)

-- Error Handler
local function errorHandler(error)
    warn("Error in Autoparry Script:", error)
    if Settings.Debug.Enabled then
        print(debug.traceback())
    end
end

-- Wrap main execution in error handler
xpcall(function()
    warn("Enhanced Autoparry Script Initialized")
end, errorHandler)