Updated:
1. Basic use
/gamemode spectator @s
/spectate @p[gamemode=survival]
The player using it must be in spectator mode. The first argument is the target to watch.
2. Make another player spectate
/spectate @e[type=zombie,limit=1,sort=nearest] Steve
The second argument is the spectator. It takes a single player only.
3. Stop spectating
/spectate
Run it without arguments, or press Shift (sneak).
4. Spectate after elimination
/execute as @a[tag=out,gamemode=!spectator] run gamemode spectator @s
/execute as @a[tag=out] run spectate @r[gamemode=adventure] @s
In a minigame, tag eliminated players with out, switch them to spectator, then attach each one to a random player who is still in the game. Run the second line once, not every tick, or the view will jump between players. Use /spectate with no arguments to let them fly freely again.
5. Fixed camera for everyone
/summon armor_stand 0 70 0 {Tags:["cam"],Invisible:1b,NoGravity:1b,Marker:1b,Rotation:[135f,0f]}
/execute as @a[gamemode=spectator] run spectate @e[type=armor_stand,tag=cam,limit=1] @s
Use execute as because the spectator argument accepts one player. Run it from a repeating command block to keep everyone locked. See the camera command.
6. Bedrock Edition
Bedrock has no /spectate. Use /camera or teleport spectators with /tp.
Troubleshooting
- Not in spectator mode: switch with /gamemode spectator first.
- Error with @a: use execute as @a run spectate ... @s.
- View jumps away: the target died or unloaded; pick a NoAI or invulnerable mob.
Check your command
The Command Error Doctor checks common syntax mistakes in your browser.