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:
| Stat | Type | Description |
|---|---|---|
startTime | number | os.clock() at run start |
endTime | number | Set on death |
deathCause | string | What killed them |
deathPosition | Vector3 | Where they died |
distanceTraveled | number | Studs walked (updated every 0.5s) |
enemiesEncountered | number | Incremented by services |
timesChased | number | Chase events |
narrowEscapes | number | Close calls |
timesHiddenInBush | number | Bush hide events |
timesEnteredDangerZone | number | Danger 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:
playerDiedremote fires with death data (cause, position)- Client plays cutscene featuring the entity that killed them
- Client delays
requestRespawnuntil cutscene finishes - Server teleports to lobby on respawn request
Remotes
| Remote | Direction | Purpose |
|---|---|---|
playerDied | Server → Client | Death notification with stats |
requestRespawn | Client → Server | Respawn request |
playerRespawned | Server → Client | Respawn confirmation |
getDeathStats | Client → Server | Request death stats |