You can't assume hv.Player to be valid, especially if/when your hook runs outside GS_STATE_GAME_PLAY, nor (I think) for it to necessarily to be a ship in some situations.
What I usually do is this:
local player = hv.Player
if player ~= nil and player:isValid() then
If you get problems when the player dies, or when you restart the mission, or when you quick restart on death, then you might want to add an extra mn.getMissionTime() > 0.1 check to that (you have a timestamp check, but it doesn't seem like it'd work across mission restarts). Quick restart especially tends to cause all sorts of unintuitive weirdness that always breaks my scripts before I add that safeguard.