Learn

J! Code Academy

Respawning the Player

Hosted by Icoso

Fix falling into the void by adding a respawn system. Create respawn.ts, import it in server.ts, then use onGameTick to read player positions and teleport anyone below a Y threshold back to spawn.

Script

Hello hello and welcome back to Jamango Academy! In this episode, we're fixing the problem of players missing jumps and falling into the void with no way of respawning. We'll write MangoLango code to check player positions and teleport them back if they've fallen off.

Positions in Jamango#

Every object in your world — players, props, spawn points — has a position stored as a Vector3 (three numbers):

  • X (left/right)
  • Y (up/down)
  • Z (forward/back)

Press the tilde (~) key to view world coordinates.

Create a new script: respawn.ts#

Create a new script file and import it from server.ts:

ts
// server.ts
import "./respawn";

Check player positions each tick#

In respawn.ts, run logic every frame and teleport below-threshold players back to spawn:

ts
// respawn.ts
import * as J from "jamango";

J.onGameTick(() => {
  const players = J.getAllPlayers();

  for (const playerId of players) {
    const position = J.getEntityPosition(playerId);

    if (position[1] < -10) {

Tip: If your obby starts elsewhere, use ~ to read coordinates and update the target position.

Test#

Jump off intentionally — if you respawn above the island, it's working! Next up: checkpoints so players don't always return to the very start.