you can get the pilot with getVehicleOccupant function and check if it exists
an example that maybe can help you
function VehicleHealth(attacker, weapon, loss)
local HealthOfVehicle = getElementHealth(source)
local driver = getVehicleOccupant(source)
if driver then
outputChatBox("life before the crash: "..math.floor(HealthOfVehicle))
outputChatBox("life after the crash: "..math.floor(HealthOfVehicle - loss))
outputChatBox("damage taken: "..math.floor(loss))
end
end
addEventHandler("onClientVehicleDamage", root, VehicleHealth)