[HELP] Start bleeding when I get shot

Hi,
I want to make function wich call function StartBleeding() when player get shot from a firegun.
I tried this code but after hitting the function star spamming the notification and StartBleeding() function

Citizen.CreateThread(function()
    while true do
        Citizen.Wait(0)
        if (HasPedBeenDamagedByWeapon(GetPlayerPed(-1), 0, 2)) then
            StartBleeding()
            exports.pNotify:SendNotification({type = 'success', text ='You started bleeding!', layout = "topRight", timeout = 3500})
        end
    end
end)

Does anyone have any advice please?

There is a native called ClearPedLastWeaponDamage, but the docs says that it doesn’t seem to work and that you should rather use HasEntityBeenDamagedByWeapon and ClearEntityLastWeaponDamage.

When I was testing those natives did not work as we need them to, so another option would be to use the low-level game event called CEventNetworkEntityDamage, it could be set up and use like so:

AddEventHandler('gameEventTriggered', function(event, args)
	if event == "CEventNetworkEntityDamage" then
		if PlayerPedId() ~= args[1] then
            return
        end
        
        if GetWeapontypeSlot(args[7]) == 0 or args[12] == 1 then
            return
        end
        
        if not bleeding then
            StartBleeding()
            exports.pNotify:SendNotification({type = 'success', text ='You started bleeding!', layout = "topRight", timeout = 3500})
        end
	end
end)

Here are some notes on the args in case you need them:

1 = victim (entity)
2 = attacker (entity)
6 = fatal (int)
7 = weapon (hash)
12 = melee (int)

Thanks man :heart: