Skip to content

playerSpectateRequest

Asks your gamemode before a player starts spectating with players.spectate, and again while they watch: when the player they watch leaves the server, and when their target goes into or out of an interior. A spectator watches across interiors unless you refuse it.

server.on("playerSpectateRequest", ({ player, target, requestReason }) =>
boolean | ViewDecision<SpectateTarget> | void | Promise<boolean | ViewDecision<SpectateTarget> | void>)
Name Type Description
player PlayerSnapshot The spectator.
target SpectateTarget Who or what they would watch. A player who has left is their ID.
requestReason "script" | "targetDisconnected" | "interiorChanged" "script": a players.spectate call. "targetDisconnected": the player they watch left. "interiorChanged": their target went into or out of an interior.

false or { decision: "deny" } refuses: a players.spectate call is rejected with view-denied, and a spectator already watching stops, with playerViewEnded’s endReason "interiorDenied". { decision: "allow", override } watches the SpectateTarget override instead. Anything else allows. See how decisions work.

When the player they watch has left ("targetDisconnected"), an override is the one chance to keep the spectator watching: without one, spectating ends.

When the player a moderator watches leaves, watch the first other player online.

gamemodes/my-mode.ts
import { players, server } from "nativemp";
server.on("playerSpectateRequest", ({ player, requestReason }) => {
if (requestReason !== "targetDisconnected") return;
const next = players.listOnline().find((other) => other.id !== player.id);
if (next) return { decision: "allow", override: { kind: "player", player: next } };
});