Skip to main content

Death & Respawn System

Death Flow

Enemy/Environment kills player
→ DeathService.killPlayer(player, cause)
→ Mark player as dead, record stats
→ humanoid.Health = 0
→ Fire playerDied remote to client
→ Client shows death UI
→ Player clicks respawn (after 3s cooldown)
→ requestRespawn remote
→ Server teleports player to lobby

Killing a Player

From any service:

import { Dependency } from "@flamework/core";
const deathService = Dependency<DeathService>();

// Instant kill
deathService.killPlayer(player, "FlowerTrap");

// Damage (returns true if player died)
const died = deathService.damagePlayer(player, 20, "RootSnare");

Run Stats

Tracked per run in RunStats:

StatTypeDescription
startTimenumberos.clock() at run start
endTimenumberSet on death
deathCausestringWhat killed them
deathPositionVector3Where they died
distanceTravelednumberStuds walked (updated every 0.5s)
enemiesEncounterednumberIncremented by services
timesChasednumberChase events
narrowEscapesnumberClose calls
timesHiddenInBushnumberBush hide events
timesEnteredDangerZonenumberDanger zone entries

Run Completion

When a player reaches the final safe zone (marker 30):

ChunkService.checkRunCompletion()
→ Detects player on SafeZone chunk at maxTrailMarker
→ Fires runCompleteCallback
→ DeathService teleports player to lobby

Respawn Cooldown

3-second cooldown between death and respawn availability. During this time, the death UI is displayed with run statistics.

Future: Death Cutscene

The system is designed for a bowling-alley-style death cutscene:

  1. playerDied remote fires with death data (cause, position)
  2. Client plays cutscene featuring the entity that killed them
  3. Client delays requestRespawn until cutscene finishes
  4. Server teleports to lobby on respawn request

Remotes

RemoteDirectionPurpose
playerDiedServer → ClientDeath notification with stats
requestRespawnClient → ServerRespawn request
playerRespawnedServer → ClientRespawn confirmation
getDeathStatsClient → ServerRequest death stats