Try this:
addEvent "onPlayerHeadshot"
addEventHandler("onPlayerDamage", getRootElement(),
function (attacker, weapon, bodypart, loss)
if ( bodypart == 9 ) and ( weapon == 34 ) then
local result = triggerEvent("onPlayerHeadshot", source, attacker, weapon, loss)
if ( result ) then
killPed(source, attacker, weapon, bodypart)
end
end
end
)