onPlayerWasted's first parameter is the total ammo of the player who died so you by writing source in there, you were trying to fetch information about the ammo's total ammo and account name which is impossible lol. So here's the fixed code.
function hp()
ammo = getPedTotalAmmo(source)
weapon = getPedWeapon(source)
playeraccount = getPlayerAccount ( source )
setAccountData(playeraccount,"weapon",weapon)
setAccountData(playeraccount,"ammo",ammo)
end
addEventHandler("onPlayerWasted",getRootElement(),hp)
addEventHandler("onPlayerSpawn",getRootElement(),
function ()
local playeraccount = getPlayerAccount ( source )
local weapon = getAccountData(playeraccount,"weapon")
local ammo = getAccountData(playeraccount,"ammo")
giveWeapon(source,weapon,ammo)
end)