Further enhance and add in an advanced health tracking to view your own health variable to see if you're taking damage or not.

```
-- Services and Player Variables
local Services = setmetatable({}, {__index = function(t, k) return game:GetService(k) end})
local P = Services.Players.LocalPlayer
local C = P.Character or P.CharacterAdded:Wait()
local H = C:WaitForChild("Humanoid")
local UIS = Services.UserInputService
local RS = Services.ReplicatedStorage

-- Bindable Events for Activation and Deactivation
local BE_Activate = Instance.new("BindableEvent")
local BE_Deactivate = Instance.new("BindableEvent")

-- Invincibility Frame Manager (IFM)
local IFM = setmetatable({
    D = 3, -- Duration of invincibility frames
    CD = 5, -- Cooldown duration
    A = false, -- Is invincibility active?
    E = {Activate = BE_Activate.Event, Deactivate = BE_Deactivate.Event}
}, {
    __index = function(t, k)
        return rawget(t, k)
    end
})

-- Health System with Health Layering (Shield)
local HS = setmetatable({}, {
    __index = function(t, k)
        if k == "H" then
            return H.Health
        elseif k == "MH" then
            return H.MaxHealth
        end
        return rawget(t, k)
    end,
    __newindex = function(t, k, v)
        if k == "H" then
            H.Health = v
        elseif k == "MH" then
            H.MaxHealth = v
        else
            rawset(t, k, v)
        end
    end
})

-- Shield Value to Represent the Extra Health Layer
local Shield = Instance.new("NumberValue")
Shield.Name = "Shield"
Shield.Value = 0
Shield.Parent = H

local ShieldActive = false
local PreviousHealth = H.Health

-- Function to Handle Damage and Apply Shield Layering
H.HealthChanged:Connect(function(newHealth)
    if ShieldActive then
        local damage = PreviousHealth - newHealth
        if damage > 0 then
            if Shield.Value > 0 then
                local shieldDamage = math.min(damage, Shield.Value)
                Shield.Value = Shield.Value - shieldDamage
                H.Health = H.Health + shieldDamage
            end
        end
    end
    PreviousHealth = H.Health
end)

-- Function to Toggle Invincibility Frames with Shield Layering
local function ToggleInvincibility()
    if not IFM.A then
        IFM.A = true
        ShieldActive = true
        Shield.Value = 50 -- Set shield amount
        BE_Activate:Fire("InvincibilityEnabled")
    
        coroutine.wrap(function()
            wait(IFM.D)
            ShieldActive = false
            Shield.Value = 0
            IFM.A = false
            BE_Deactivate:Fire("InvincibilityDisabled")
            wait(IFM.CD)
        end)()
    end
end

-- Proximity Check to Activate Invincibility Frames
local function ProximityCheck()
    local CP = C:FindFirstChild("HumanoidRootPart")
    if not CP then return end
    local pos = CP.Position
    for _, OP in ipairs(Services.Players:GetPlayers()) do
        if OP ~= P and OP.Character then
            local OCP = OP.Character:FindFirstChild("HumanoidRootPart")
            if OCP and (pos - OCP.Position).Magnitude <= 10 and not IFM.A then
                ToggleInvincibility()
                break
            end
        end
    end
end

-- Input Handler for Manual Activation (e.g., Left Mouse Click)
local function InputHandler()
    UIS.InputBegan:Connect(function(input, gp)
        if not gp then
            if input.UserInputType == Enum.UserInputType.MouseButton1 then
                ProximityCheck()
            end
        end
    end)
end

-- Continuous Proximity Check and Input Handling
Services.RunService.Heartbeat:Connect(function()
    ProximityCheck()
end)

coroutine.wrap(function()
    InputHandler()
    while true do
        ProximityCheck()
        wait(0.5)
    end
end)()

-- Status Effects Management
local StatusEffects = setmetatable({}, {
    __index = function(t, k)
        return rawget(t, k) or {}
    end
})

local function ApplyStatusEffect(player, effect, duration)
    table.insert(StatusEffects[player.Name], {Effect = effect, Time = os.time() + duration})
    -- Fire an event or handle visual effects here
end

local function RemoveExpiredEffects()
    for _, player in ipairs(Services.Players:GetPlayers()) do
        local effects = StatusEffects[player.Name]
        if effects then
            for i = #effects, 1, -1 do
                if effects[i].Time <= os.time() then
                    -- Handle effect removal here
                    table.remove(effects, i)
                end
            end
        end
    end
end

coroutine.wrap(function()
    while true do
        RemoveExpiredEffects()
        wait(1)
    end
end)()

-- Event Connections for Invincibility Activation and Deactivation
IFM.E.Activate:Connect(function(eventName)
    if eventName == "InvincibilityEnabled" then
        ApplyStatusEffect(P, "Shield", IFM.D)
        -- Additional code for visual effects or notifications
    end
end)

IFM.E.Deactivate:Connect(function(eventName)
    if eventName == "InvincibilityDisabled" then
        -- Additional code for when invincibility ends
    end
end)