Player Death

Hello i have created a script which revives the Player after a amount of secounds when then killed with a specifig weapon.

local classes = {
    ["weapon_lightsaber_training"] = true,
    ["weapon_fists"] = true,
    ["weapon_lightsaber_dual_training"] = true,
    ["weapon_frag"] = true,
    ["weapon_lightsaber_shock"] = true,
}

hook.Add("DoPlayerDeath", "Unique_Name", function(victim, attacker, damageInfo)

local weapon = attacker:GetActiveWeapon()

if weapon:IsValid() and classes[weapon:GetClass()] or weapon:IsAttached("trainammo") then
        timer.Simple(10, function()
            if victim:IsValid() then
               victim:revive()
            end
        end)
    end
end)

But my problem is when i get killed by Fall DMG there is no attacker and it dose not spawn a Ragedoll. If someone know how i do it that the Ragedoll spawns pls tell me how i should do this.

You’ll want to check if attacker is valid the same way you’re checking weapon:IsValid() and return early if it isn’t, that should fix your issue.

if attacker:IsValid() and weapon:IsValid() and classes[weapon:GetClass()] or weapon:IsAttached("trainammo") then
        timer.Simple(10, function()
            if victim:IsValid() then
               victim:revive()
            end
        end)
    else
        return
    end

Like this?

Even earlier, use a separate if statement that you place before your local weapon = attacker:GetActiveWeapon() code.

Should i do the If Statement around the Other one so that it is like

 if attacker:IsValid() then
     the if statement with revive
 else
     return
  end
hook.Add("DoPlayerDeath", "Unique_Name", function(victim, attacker, damageInfo)
    if not attacker:IsValid() then
         return
    end

    -- The rest of your code
end)

Yeah that was it thx. The Only this that dosen’t work is when i kill someone with a Lightsaber from WOS ALCS
but i think i can try something to fix that. Thank you very very much

1 Like