Further enhance and add in an advanced pre-field invincibility frames with humanoid onstate change.

```
local Services = setmetatable({}, {
    __index = function(t, k) return game:GetService(k) end,
    __newindex = function() error("Attempt to modify read-only service proxy") end
})

-- Enhanced Health Service Handler
local HealthService = {
    _internal = {},
    _cache = setmetatable({}, {__mode = "k"}),
    _handlers = {}
}

-- Advanced Health Metatable
local HealthMetatable = {
    __index = function(self, key)
        if HealthService._internal[key] then
            return HealthService._internal[key]
        end
        return rawget(self, key)
    end,
    
    __newindex = function(self, key, value)
        if HealthService._handlers[key] then
            HealthService._handlers[key](value)
            return
        end
        rawset(self, key, value)
    end,
    
    __call = function(self, ...)
        return HealthService.Initialize(...)
    end
}

-- Enhanced Health Value Handler
local HealthValueHandler = setmetatable({
    _values = {},
    _connections = {}
}, {
    __index = function(self, key)
        local value = self._values[key]
        if not value then
            value = Instance.new("NumberValue")
            value.Name = "Health_" .. key
            self._values[key] = value
        end
        return value
    end,
    
    __newindex = function(self, key, value)
        if typeof(value) == "number" then
            if not self._values[key] then
                self._values[key] = Instance.new("NumberValue")
                self._values[key].Name = "Health_" .. key
            end
            self._values[key].Value = value
        end
    end
})

-- Initialize the enhanced health system
function HealthService.Initialize(character)
    local humanoid = character:WaitForChild("Humanoid")
    local healthValue = Instance.new("NumberValue")
    healthValue.Name = "CustomHealth"
    healthValue.Value = humanoid.Health
    healthValue.Parent = character
    
    -- Create proxy for health manipulation
    local proxy = setmetatable({
        _humanoid = humanoid,
        _healthValue = healthValue,
        _regenerating = false
    }, {
        __index = function(t, k)
            if k == "Health" then
                return t._healthValue.Value
            end
            return rawget(t, k)
        end,
        
        __newindex = function(t, k, v)
            if k == "Health" then
                t._healthValue.Value = v
                t._humanoid.Health = v
            else
                rawset(t, k, v)
            end
        end
    })
    
    HealthService._cache[character] = proxy
    return proxy
end

-- Advanced health manipulation functions
function HealthService.ApplyHealthModifier(character, modifier)
    local proxy = HealthService._cache[character]
    if proxy then
        local currentHealth = proxy.Health
        proxy.Health = math.clamp(currentHealth + modifier, 0, proxy._humanoid.MaxHealth)
    end
end

function HealthService.EnableHealthRegeneration(character, rate, interval)
    local proxy = HealthService._cache[character]
    if proxy and not proxy._regenerating then
        proxy._regenerating = true
        
        coroutine.wrap(function()
            while proxy._regenerating do
                if proxy.Health < proxy._humanoid.MaxHealth then
                    HealthService.ApplyHealthModifier(character, rate)
                end
                wait(interval or 1)
            end
        end)()
    end
end

-- Integrate with existing IFM system
local IFM = setmetatable({
    Duration = 3,
    Cooldown = 5,
    Active = false,
    LastActivation = 0,
    FrameBuffer = {},
    MaxFrameBufferSize = 120,
    Events = {Activate = BE.Event, Deactivate = BE.Event},
    StateStack = {},
    QuaternionCache = setmetatable({}, {__mode = "k"}),
    HealthHandler = HealthService
}, {
    __index = function(self, k)
        if k == "CurrentState" then
            return #self.StateStack > 0 and self.StateStack[#self.StateStack] or nil
        end
        return rawget(self, k)
    end
})

-- Modified ApplyInvincibilityFrame function
local function ApplyInvincibilityFrame(duration)
    if tick() - IFM.LastActivation < IFM.Cooldown then return false end
    
    IFM.Active = true
    IFM.LastActivation = tick()
    
    local healthProxy = IFM.HealthHandler.Initialize(C)
    local originalState = {
        Health = healthProxy.Health,
        MaxHealth = H.MaxHealth,
        WalkSpeed = H.WalkSpeed,
        JumpPower = H.JumpPower
    }
    
    table.insert(IFM.StateStack, originalState)
    
    healthProxy.Health = math.huge
    H.MaxHealth = math.huge
    H.WalkSpeed = H.WalkSpeed * 1.5
    
    -- Enable health regeneration during invincibility
    IFM.HealthHandler.EnableHealthRegeneration(C, 10, 0.5)
    
    coroutine.wrap(function()
        local startTime = tick()
        while tick() - startTime < duration do
            ProcessFrameBuffer()
            wait(Configuration.FRAME_BUFFER)
        end
        
        if #IFM.StateStack > 0 then
            local prevState = table.remove(IFM.StateStack)
            healthProxy.Health = prevState.Health
            H.MaxHealth = prevState.MaxHealth
            H.WalkSpeed = prevState.WalkSpeed
            H.JumpPower = prevState.JumpPower
        end
        
        IFM.Active = false
        IFM.QuaternionCache[C] = nil
        
        wait(IFM.Cooldown - duration)
    end)()
    
    return true
end