Npc bodies disappearing

Hi im kind of new to coding but I’m trying to make it so when an npc dies it’s corpse/ragdoll dissapears after 5 seconds.
Is this possible and how would I go about doing it?

If keep corpses convar is checked use this code:


hook.Add("CreateEntityRagdoll", "rem_rags_timed", function(ent, rag)
    if ent:IsNPC() then
        timer.Simple(<<your delay time>>, function()
        if ValidEntity(rag) then rag:Remove() end
        end)
    end
end)

There are ways to remove the other type of ragdolls, but I think they automatically remove them selves.