Skip to content

playerDisconnected

Tells your gamemode when a player leaves, for any reason: they quit, timed out, were kicked or banned.

Renamed in 0.28 from disconnect; see renamed names.

server.on("playerDisconnected", async ({ player, reason }, { signal }) => void)
Name Type Description
player PlayerSnapshot The player.
reason string Why, as the server recorded it: disconnected when they simply left.

Save a player’s data when they leave.

The session retires immediately. Cleanup runs once through reserved capacity and can overlap an old handler’s uncooperative I/O. It may save external state and broadcast a departure; targeting the departed PlayerSnapshot fails. Its signal follows the runtime lifetime. Cancellation cannot roll back a query or your own map writes. See Async handlers and player sessions.

gamemodes/my-mode.ts
import { server } from "nativemp";
server.on("playerDisconnected", async ({ player, reason }) => {
server.log(`${player.name} left (${reason})`);
// await saveAccount(player.name);
});