[HELP] Script doesn't activate when I respawn

Hi, I need help. Script is working fine, but when I die and reach 40HP again, the script doesn’t activate.

Citizen.CreateThread(
    function()
        while true do
            Citizen.Wait(0)
            local hp = Citizen.InvokeNative(0x82368787EA73C0F7, PlayerPedId())
            local dead = Citizen.InvokeNative(0x3317DEDB88C95038, PlayerPedId(), true)
            local health
            local x, y, z = table.unpack(GetEntityCoords(PlayerPedId()))
            local playerPed = PlayerPedId()
            if (hp == false or hp >= 41) then
                TriggerEvent("nic_injury:off")  
                print("injury-off")   
            elseif (hp == false or hp <= 40) then
                Citizen.Wait(0)
                TriggerEvent("nic_injury:on")
                print("injury-on") 
                Citizen.Wait(5000)
                SetEntityHealth(playerPed, 40, 0)
                Blackout()
                print("hp-pridani")
                while true do
                    Citizen.Wait(100)
                    if IsEntityDead(playerPed) then
                        TriggerEvent("nic_injury:off")
                    end
                end
            end 
            if ragdoll then
                Blackout(x, y, z, hp)
            end
        end
    end
)