FiveM death and revive system: last stand, respawn and state bags

How a FiveM death system works: last stand vs dead, respawn timer, reviving from admin or EMS, syncing the dead state with state bags, and fixing combat logging.

The symptom: a player dies and sees no respawn option, or cannot be revived, or logs out while dead and comes back at full health.

Death in FiveM is not one feature. The game only knows that a ped has zero health. Everything else (the downed animation, the timer, the revive) is built by your framework and ambulance resource. This article explains the moving parts so you can find which one is broken.

What the game knows

The engine tells you a ped is dead, nothing more. Resources detect it with a native check or with the damage game event, then take over:

lua
-- client
CreateThread(function()
    local wasDead = false
    while true do
        Wait(500)
        local dead = IsEntityDead(PlayerPedId())
        if dead and not wasDead then
            TriggerServerEvent('myjob:playerDied')
        end
        wasDead = dead
    end
end)

The ESX core fires a death event for scripts to listen to, and QBCore keeps flags in the player's metadata. In both, your ambulance resource listens for death and runs the rest.

Last stand vs death

Many setups have two stages:

State What the player can do How it ends
Last stand (downed) Crawl, call for help, wait Revived by EMS, or the timer runs out and they die
Dead Nothing, the screen shows a respawn timer Respawn at the hospital, or a revive

QBCore-style setups expose this as separate flags (a last stand flag and a dead flag). ESX setups usually have only the dead state. Pick what your server needs and do not mix two ambulance resources, because each one tracks its own flags and they fight over the ped.

The respawn timer

The timer is a client countdown with a server rule behind it. Two settings matter most:

  • Respawn time: how long before the player may press a key to respawn.
  • Bleed out time (if you use last stand): how long before the downed player dies.

If the respawn key does nothing, the cause is almost always that the timer never started because the dead flag was never set. Check the console for errors at the moment of death.

Respawning must reset several things together: health, the dead flag, the death animation, the screen effects, and the position at the hospital. If you reset only health, the player gets up inside the dead animation.

Reviving from admin or EMS

Most frameworks and ambulance resources ship a /revive style command for admins, and an EMS action for players on the job. They all end up doing the same thing on the client:

lua
-- client: bring the local player back at their current position
local ped = PlayerPedId()
local coords = GetEntityCoords(ped)

NetworkResurrectLocalPlayer(coords.x, coords.y, coords.z, GetEntityHeading(ped), true, false)
ClearPedTasksImmediately(ped)
SetEntityHealth(ped, GetEntityMaxHealth(ped))
ClearPedBloodDamage(ped)

Then the resource clears its dead flag. If you only call the natives and skip the flag, the player is alive in the world but still "dead" for the framework, and the respawn screen stays up. Use the revive function of your ambulance resource whenever you can, and write your own only when you are replacing it.

Warning: the revive command must be restricted by permission, and by job for the EMS version. See ACE permissions for the admin side.

Syncing the dead state with state bags

Other players, and other scripts, need to know someone is dead: EMS blips, a "do not rob a dead player" check, an inventory that refuses to open. Polling each client is slow. A state bag is the natural fit, because late joiners see it too:

lua
-- server
RegisterNetEvent('myjob:playerDied', function()
    local src = source
    Player(src).state:set('isDead', true, true)
end)

local function revive(src)
    Player(src).state:set('isDead', false, true)
    TriggerClientEvent('myjob:revive', src)
end
lua
-- any script, server
if Player(targetSrc).state.isDead then
    -- allow the revive action
end

Use a name that your other scripts also read, or the flag helps nobody. Some frameworks already keep a dead flag in player data, so check that first and read it instead of making a second source of truth.

Combat logging

A player who disconnects while dead or downed, then reconnects, should still be dead. Without that, killing someone does nothing.

  1. On playerDropped, check whether the player was dead and store that in the database with the character.
  2. When the character loads, read the flag and put them back in the dead or last stand state.
  3. Make the respawn timer start again, or keep the remaining time if you want to be strict.
lua
AddEventHandler('playerDropped', function()
    local src = source
    if Player(src).state.isDead then
        -- save the dead flag for this character
    end
end)

Where the flag is saved depends on your framework. Many ambulance resources already keep a dead flag in the database, so look for it before you add a second one. Also guard against the reverse: a player who is stuck dead after a crash needs an admin revive, which is why the command above should exist.

Checklist

Symptom Fix
Respawn key does nothing The dead flag never got set: look for a script error at the moment of death
Player revived but screen still says dead Clear the framework's dead flag, not only the health
Player gets up in the death animation Clear tasks and reset the ped after respawn
Two ambulance scripts fighting Run only one death system
Others cannot see who is dead Set a replicated state bag on the player
Player comes back alive after logging out Save the dead flag on playerDropped and restore it on load

Quick answers

How do I revive a player as an admin?

Most frameworks and ambulance resources include a /revive style admin command. The name and the permission it needs depend on your resources, so check your ambulance or admin menu resource.

What is the difference between last stand and dead?

Last stand is a downed state where the player can crawl or wait to be helped. Dead is the final state where only a respawn or a revive brings them back. Not every framework has both.

How do I stop players from combat logging while dead?

Save the dead state when the player leaves and apply it again when they load back in. If the dead flag is not stored, the player comes back alive.

Scripts that skip this problem

Mic PhoneA foldable phone that unfolds into a tablet and carries onto a player's real phone.View script →Item Creator V2Create usable items with animations, props, effects and more — without writing code.View script →

Keep reading