Tutorial · Game systems

How to make a spectate system in Roblox Studio

Round games need a spectate button: once you are out, you want to watch the players still in. The camera already knows how to follow a character, because that is what it does for your own. Spectating is telling it to follow someone else's instead. This guide builds the button, the arrows to switch players, and the small fixes that stop the camera breaking when the person you watch dies or leaves.

Updated 14 November 20267 min readBeginnerLuauWritten by

In short

In a LocalScript in StarterGui, set workspace.CurrentCamera.CameraSubject to another player's Humanoid. Keep a list of the other living players and step through it with Next and Previous buttons. To stop, set CameraSubject back to your own Humanoid. Re-apply the subject when the watched player respawns, and move on when they die or leave.

  • CameraSubject is set on the client, because each player has their own camera. No server code is needed for the basic version.
  • Use the Humanoid, not the HumanoidRootPart, as the subject. The default camera then behaves exactly like it does for your own character.
  • With StreamingEnabled, far-away areas may not be loaded on your device. A small server script moves your ReplicationFocus to the player you watch (Step 3).

Get the script

Spectate script with next and previous buttons

A LocalScript that adds a Spectate button and arrows, points the camera at other living players in turn, follows their respawns and returns to you when you stop.

LocalScript in StarterGui named Spectate
-- LocalScript in StarterGui named Spectate.
-- A Spectate button plus previous and next arrows that point the camera at other living players.
local Players = game:GetService("Players")
local ReplicatedStorage = game:GetService("ReplicatedStorage")
local UserInputService = game:GetService("UserInputService")

local SKIP_AFTER_DEATH = 2 -- seconds to keep watching a player who died
local PREVIOUS_KEY = Enum.KeyCode.Q
local NEXT_KEY = Enum.KeyCode.E

local player = Players.LocalPlayer
local camera = workspace.CurrentCamera

-- ---------- The buttons ----------
local gui = Instance.new("ScreenGui")
gui.Name = "SpectateGui"
gui.ResetOnSpawn = false

local bar = Instance.new("Frame")
bar.AnchorPoint = Vector2.new(0.5, 1)
bar.Position = UDim2.new(0.5, 0, 1, -16)
bar.Size = UDim2.fromOffset(340, 44)
bar.BackgroundTransparency = 1
bar.Parent = gui

local function makeButton(text: string, x: number, width: number): TextButton
	local button = Instance.new("TextButton")
	button.Position = UDim2.fromOffset(x, 0)
	button.Size = UDim2.fromOffset(width, 44)
	button.BackgroundColor3 = Color3.fromRGB(30, 30, 40)
	button.TextColor3 = Color3.new(1, 1, 1)
	button.Font = Enum.Font.GothamBold
	button.TextSize = 16
	button.Text = text
	button.Parent = bar
	Instance.new("UICorner").Parent = button
	return button
end

local previousButton = makeButton("<", 0, 44)
local toggleButton = makeButton("Spectate", 52, 236)
local nextButton = makeButton(">", 296, 44)
previousButton.Visible = false
nextButton.Visible = false

gui.Parent = player:WaitForChild("PlayerGui")

-- ---------- Spectating ----------
local spectating = false
local target: Player? = nil
local targetConnections: { RBXScriptConnection } = {}

-- Tell the server who we watch, so streaming loads around them (Step 3). Optional.
local focusEvent = ReplicatedStorage:FindFirstChild("SpectateTarget")

local function aliveHumanoid(other: Player): Humanoid?
	local character = other.Character
	local humanoid = character and character:FindFirstChildOfClass("Humanoid")
	if humanoid and humanoid.Health > 0 then
		return humanoid
	end
	return nil
end

-- Everyone we could watch: other players who are alive, in join order
local function candidates(): { Player }
	local list = {}
	for _, other in Players:GetPlayers() do
		if other ~= player and aliveHumanoid(other) then
			table.insert(list, other)
		end
	end
	return list
end

local function clearTargetConnections()
	for _, connection in targetConnections do
		connection:Disconnect()
	end
	table.clear(targetConnections)
end

local function watchOwnCharacter()
	local character = player.Character
	local humanoid = character and character:FindFirstChildOfClass("Humanoid")
	if humanoid then
		camera.CameraSubject = humanoid
	end
end

local setTarget: (Player?) -> ()
local step: (number) -> ()

local function pointCamera()
	local humanoid = target and target.Character and target.Character:FindFirstChildOfClass("Humanoid")
	if humanoid then
		camera.CameraSubject = humanoid
	end
end

setTarget = function(newTarget: Player?)
	clearTargetConnections()
	target = newTarget
	if focusEvent and focusEvent:IsA("RemoteEvent") then
		focusEvent:FireServer(newTarget)
	end
	if not newTarget then
		toggleButton.Text = if spectating then "Nobody to watch" else "Spectate"
		watchOwnCharacter()
		return
	end
	toggleButton.Text = newTarget.DisplayName
	pointCamera()
	-- They respawned: follow the new character
	table.insert(targetConnections, newTarget.CharacterAdded:Connect(function(character: Model)
		character:WaitForChild("Humanoid", 5)
		if target == newTarget then
			pointCamera()
			-- The old root part is gone, so send the new one to the server for streaming
			if focusEvent and focusEvent:IsA("RemoteEvent") then
				focusEvent:FireServer(newTarget)
			end
		end
	end))
	-- They died: wait a moment, then move on to someone alive
	local humanoid = aliveHumanoid(newTarget)
	if humanoid then
		table.insert(targetConnections, humanoid.Died:Connect(function()
			task.wait(SKIP_AFTER_DEATH)
			if spectating and target == newTarget then
				step(1)
			end
		end))
	end
end

-- Move forward (1) or back (-1) through the list of living players
step = function(direction: number)
	local list = candidates()
	if #list == 0 then
		setTarget(nil)
		return
	end
	local found = if target then table.find(list, target) else nil
	-- Wrap round at the ends; start at the first player if the old target is gone
	local index = if found then (found - 1 + direction) % #list + 1 else 1
	setTarget(list[index])
end

local function setSpectating(on: boolean)
	spectating = on
	previousButton.Visible = on
	nextButton.Visible = on
	if on then
		step(1)
	else
		setTarget(nil)
	end
end

toggleButton.Activated:Connect(function()
	setSpectating(not spectating)
end)
previousButton.Activated:Connect(function()
	step(-1)
end)
nextButton.Activated:Connect(function()
	step(1)
end)

UserInputService.InputBegan:Connect(function(input: InputObject, gameProcessed: boolean)
	if gameProcessed or not spectating then
		return
	end
	if input.KeyCode == PREVIOUS_KEY then
		step(-1)
	elseif input.KeyCode == NEXT_KEY then
		step(1)
	end
end)

-- The watched player left: switch to the next one
Players.PlayerRemoving:Connect(function(leaving: Player)
	if leaving == target then
		target = nil
		if spectating then
			step(1)
		end
	end
end)

-- Our own respawn makes the default camera point at us again, so put it back
player.CharacterAdded:Connect(function()
	if spectating then
		task.wait(0.1)
		pointCamera()
	end
end)

RoCode builds it in the place you have open in Roblox Studio, on Windows or macOS with a desktop browser; on a phone the button sends the prompt and the link to your computer. Free to start, with free credits every day. More Roblox Studio scripts

Where to put it

Explorer: one LocalScript, plus an optional server script
StarterGui
  Spectate LocalScript new
ServerScriptService
  SpectateFocus Script (new, optional)

Settings you can change

SKIP_AFTER_DEATHIn the script
Seconds the camera stays on a player who died before it moves on to the next living player. Default: 2.
PREVIOUS_KEYIn the script
Keyboard key for the previous player while spectating. Default: Enum.KeyCode.Q.
NEXT_KEYIn the script
Keyboard key for the next player while spectating. Default: Enum.KeyCode.E.

Test with at least two players: Test tab, Clients and Servers, 2 players, Start. With one player there is nobody to watch.

Type-checked with luau-lsp strict against Roblox's API definitions on 14 November 2026. Not playtested in Studio yet: press Play and watch the Output window before you publish.

Prompt for RoCode

Add a spectate system to my game: a LocalScript in StarterGui with a Spectate button at the bottom of the screen and previous and next arrows with the watched player's name, that sets the camera subject to other living players' Humanoids, follows them when they respawn, moves on 2 seconds after they die or when they leave, uses Q and E keys, and returns the camera to me when I stop.

On this page
  1. Get the script
  2. How it works
  3. 1. Spectate script
  4. 2. How it works
  5. 3. Streaming
  6. 4. Round games
  7. 5. Test
  8. Common errors
  9. With RoCode
  10. Questions
  11. Sources

How spectating works

Every player has their own Camera object, workspace.CurrentCamera, and Roblox's default camera scripts make it orbit whatever its CameraSubject is. Normally that is your own Humanoid. Set it to another player's Humanoid and your camera orbits them instead, with zoom and rotation still working. Your character stays where it is.

What can go wrong, and the fix in this guide
ProblemWhyFix
The camera freezes when the watched player diesTheir old Humanoid is destroyed when they respawnListen for CharacterAdded and point at the new Humanoid
The camera freezes when they leaveTheir character is removedListen for PlayerRemoving and switch to the next player
Your own respawn snaps the camera backThe default camera scripts point at your new characterRe-apply the subject after you respawn
A far player shows up as empty spaceStreamingEnabled has not loaded that area on your deviceMove your ReplicationFocus on the server (Step 3)

Step 1: The spectate script

  1. Hover over StarterGui in the Explorer, click + and insert a LocalScript. Name it Spectate.
  2. Paste the code below. It builds its own buttons, so there is nothing else to make.
LocalScript in StarterGui named Spectate
-- LocalScript in StarterGui named Spectate.
-- A Spectate button plus previous and next arrows that point the camera at other living players.
local Players = game:GetService("Players")
local ReplicatedStorage = game:GetService("ReplicatedStorage")
local UserInputService = game:GetService("UserInputService")

local SKIP_AFTER_DEATH = 2 -- seconds to keep watching a player who died
local PREVIOUS_KEY = Enum.KeyCode.Q
local NEXT_KEY = Enum.KeyCode.E

local player = Players.LocalPlayer
local camera = workspace.CurrentCamera

-- ---------- The buttons ----------
local gui = Instance.new("ScreenGui")
gui.Name = "SpectateGui"
gui.ResetOnSpawn = false

local bar = Instance.new("Frame")
bar.AnchorPoint = Vector2.new(0.5, 1)
bar.Position = UDim2.new(0.5, 0, 1, -16)
bar.Size = UDim2.fromOffset(340, 44)
bar.BackgroundTransparency = 1
bar.Parent = gui

local function makeButton(text: string, x: number, width: number): TextButton
	local button = Instance.new("TextButton")
	button.Position = UDim2.fromOffset(x, 0)
	button.Size = UDim2.fromOffset(width, 44)
	button.BackgroundColor3 = Color3.fromRGB(30, 30, 40)
	button.TextColor3 = Color3.new(1, 1, 1)
	button.Font = Enum.Font.GothamBold
	button.TextSize = 16
	button.Text = text
	button.Parent = bar
	Instance.new("UICorner").Parent = button
	return button
end

local previousButton = makeButton("<", 0, 44)
local toggleButton = makeButton("Spectate", 52, 236)
local nextButton = makeButton(">", 296, 44)
previousButton.Visible = false
nextButton.Visible = false

gui.Parent = player:WaitForChild("PlayerGui")

-- ---------- Spectating ----------
local spectating = false
local target: Player? = nil
local targetConnections: { RBXScriptConnection } = {}

-- Tell the server who we watch, so streaming loads around them (Step 3). Optional.
local focusEvent = ReplicatedStorage:FindFirstChild("SpectateTarget")

local function aliveHumanoid(other: Player): Humanoid?
	local character = other.Character
	local humanoid = character and character:FindFirstChildOfClass("Humanoid")
	if humanoid and humanoid.Health > 0 then
		return humanoid
	end
	return nil
end

-- Everyone we could watch: other players who are alive, in join order
local function candidates(): { Player }
	local list = {}
	for _, other in Players:GetPlayers() do
		if other ~= player and aliveHumanoid(other) then
			table.insert(list, other)
		end
	end
	return list
end

local function clearTargetConnections()
	for _, connection in targetConnections do
		connection:Disconnect()
	end
	table.clear(targetConnections)
end

local function watchOwnCharacter()
	local character = player.Character
	local humanoid = character and character:FindFirstChildOfClass("Humanoid")
	if humanoid then
		camera.CameraSubject = humanoid
	end
end

local setTarget: (Player?) -> ()
local step: (number) -> ()

local function pointCamera()
	local humanoid = target and target.Character and target.Character:FindFirstChildOfClass("Humanoid")
	if humanoid then
		camera.CameraSubject = humanoid
	end
end

setTarget = function(newTarget: Player?)
	clearTargetConnections()
	target = newTarget
	if focusEvent and focusEvent:IsA("RemoteEvent") then
		focusEvent:FireServer(newTarget)
	end
	if not newTarget then
		toggleButton.Text = if spectating then "Nobody to watch" else "Spectate"
		watchOwnCharacter()
		return
	end
	toggleButton.Text = newTarget.DisplayName
	pointCamera()
	-- They respawned: follow the new character
	table.insert(targetConnections, newTarget.CharacterAdded:Connect(function(character: Model)
		character:WaitForChild("Humanoid", 5)
		if target == newTarget then
			pointCamera()
			-- The old root part is gone, so send the new one to the server for streaming
			if focusEvent and focusEvent:IsA("RemoteEvent") then
				focusEvent:FireServer(newTarget)
			end
		end
	end))
	-- They died: wait a moment, then move on to someone alive
	local humanoid = aliveHumanoid(newTarget)
	if humanoid then
		table.insert(targetConnections, humanoid.Died:Connect(function()
			task.wait(SKIP_AFTER_DEATH)
			if spectating and target == newTarget then
				step(1)
			end
		end))
	end
end

-- Move forward (1) or back (-1) through the list of living players
step = function(direction: number)
	local list = candidates()
	if #list == 0 then
		setTarget(nil)
		return
	end
	local found = if target then table.find(list, target) else nil
	-- Wrap round at the ends; start at the first player if the old target is gone
	local index = if found then (found - 1 + direction) % #list + 1 else 1
	setTarget(list[index])
end

local function setSpectating(on: boolean)
	spectating = on
	previousButton.Visible = on
	nextButton.Visible = on
	if on then
		step(1)
	else
		setTarget(nil)
	end
end

toggleButton.Activated:Connect(function()
	setSpectating(not spectating)
end)
previousButton.Activated:Connect(function()
	step(-1)
end)
nextButton.Activated:Connect(function()
	step(1)
end)

UserInputService.InputBegan:Connect(function(input: InputObject, gameProcessed: boolean)
	if gameProcessed or not spectating then
		return
	end
	if input.KeyCode == PREVIOUS_KEY then
		step(-1)
	elseif input.KeyCode == NEXT_KEY then
		step(1)
	end
end)

-- The watched player left: switch to the next one
Players.PlayerRemoving:Connect(function(leaving: Player)
	if leaving == target then
		target = nil
		if spectating then
			step(1)
		end
	end
end)

-- Our own respawn makes the default camera point at us again, so put it back
player.CharacterAdded:Connect(function()
	if spectating then
		task.wait(0.1)
		pointCamera()
	end
end)

Step 2: How the script works

  • candidates() builds a fresh list every time you press an arrow: every other player whose Humanoid has health above 0. Players who joined or died since the last press are handled for free.
  • step(direction) finds the current target in that list and moves one place forward or back, wrapping round at the ends with %. If the target is no longer in the list (they died), it starts at the first living player.
  • setTarget points the camera, writes the player's display name on the button, and connects two events for that player only: CharacterAdded to follow their respawn, and Died to move on after SKIP_AFTER_DEATH seconds. Switching target disconnects them, so old players never steal the camera back.
  • Stopping sets the subject back to your own Humanoid, which is what the default camera expects.

Step 3: Load far players with streaming (optional)

Check StreamingEnabled on Workspace in the Properties window. When it is ticked, your device only loads the map near your character. Spectate someone on the far side of a big map and you can end up looking at a character standing in empty space.

Each Player has a ReplicationFocus property that sets the part streaming is centred on. Roblox's reference says to set it only from a server Script, and that nil goes back to the default, the player's own character. So the LocalScript tells the server who it is watching, and the server moves the focus.

  1. Hover over ServerScriptService, click +, insert a Script named SpectateFocus and paste the code below.
  2. The Spectate LocalScript finds the SpectateTarget RemoteEvent this script makes and uses it automatically. If your place does not use streaming, you can skip this step.
Script in ServerScriptService named SpectateFocus
-- Script in ServerScriptService named SpectateFocus.
-- Moves a spectator's ReplicationFocus to the player they watch, so streaming loads that area.
local Players = game:GetService("Players")
local ReplicatedStorage = game:GetService("ReplicatedStorage")

local MIN_SECONDS_BETWEEN = 0.2 -- ignore requests faster than this

local spectateTarget = Instance.new("RemoteEvent")
spectateTarget.Name = "SpectateTarget"
spectateTarget.Parent = ReplicatedStorage

local lastRequest: { [Player]: number } = {}

spectateTarget.OnServerEvent:Connect(function(player: Player, target: unknown)
	local now = os.clock()
	if now - (lastRequest[player] or 0) < MIN_SECONDS_BETWEEN then
		return
	end
	lastRequest[player] = now

	-- nil means "stop spectating": back to the default, the player's own character
	if target == nil then
		player.ReplicationFocus = nil
		return
	end
	-- Only accept a real player who is still in the game, never any other Instance
	if typeof(target) ~= "Instance" or not target:IsA("Player") or target.Parent ~= Players or target == player then
		return
	end
	local character = target.Character
	local root = character and character:FindFirstChild("HumanoidRootPart")
	if root and root:IsA("BasePart") then
		player.ReplicationFocus = root
	end
end)

Players.PlayerRemoving:Connect(function(player: Player)
	lastRequest[player] = nil
	-- Anyone watching the leaving player goes back to their own focus
	for _, other in Players:GetPlayers() do
		local focus = other.ReplicationFocus
		if focus and player.Character and focus:IsDescendantOf(player.Character) then
			other.ReplicationFocus = nil
		end
	end
end)

The server checks what the client sends: it must be nil or a Player who is still in the game, and requests are limited to five a second. Without the checks, an exploiter could send any part in the game as the focus. Setting your own focus elsewhere gives nothing away that the camera does not already show, but checking is a good habit for every RemoteEvent; the RemoteEvents guide explains why.

When the watched player respawns, their old root part is destroyed, so the LocalScript's CharacterAdded handler fires SpectateTarget again and the server focuses on the new character.

Step 4: Spectate only when you are out

In a round game you usually want the button only for players who are not in the round, and spectating only of players who are. Two small changes do that, if your round script marks players with an attribute such as InRound (the round system guide keeps a list you can turn into one):

  • In candidates(), add and other:GetAttribute("InRound") == true to the if, so only players in the round can be watched.
  • Listen for player:GetAttributeChangedSignal("InRound"): hide bar while you are in the round, and call setSpectating(false) when the round puts you back in.

A common extra is to start spectating automatically when you are eliminated: call setSpectating(true) when your InRound attribute turns false.

Step 5: Test it

  1. Open the Test tab, set Clients and Servers to 2 or 3 players and press Start. Studio opens a window per player.
  2. In one player's window, click Spectate. The camera jumps to another player and the button shows their name.
  3. Press > or E to go to the next player and < or Q to go back.
  4. In the watched player's window, reset the character (Esc, Reset Character). After 2 seconds the spectator moves on; with only two players it shows "Nobody to watch" until they respawn and you press an arrow.
  5. Click the button again to stop. The camera returns to your own character.

Common errors and fixes

Most spectate problems are the camera pointing at something that no longer exists.

The button says Nobody to watch

Nobody else is alive in the server. In Play Solo you are alone: test with 2 or more players from the Test tab.

The camera gets stuck in one place

It is pointing at a Humanoid that was destroyed. Check you copied the CharacterAdded part of setTarget, which follows a respawn.

I see the player but not the map around them

StreamingEnabled has not loaded that area. Add the SpectateFocus script from Step 3.

The buttons cover my other GUI

Change bar.Position. UDim2.new(0.5, 0, 1, -16) is bottom centre; UDim2.new(0.5, 0, 0, 60) puts it near the top.

Build it with RoCode

If you would rather not set it up by hand, RoCode can add spectating to the place you have open. RoCode is an independent AI agent for Roblox Studio, not made by Roblox: you describe the change in a web chat, and its Studio plugin creates the scripts in your Explorer.

You type

Add spectating to my round game: when a player is eliminated, show a spectate bar with arrows to watch the players still in the round, and hide it when the next round starts.

RoCode does
  • Can read your place first to find how your round script tracks who is still in
  • Writes the scripts with Create Script and is told to compile-check each one with Check Script
  • Sets an undo point before and after each batch of changes, so Ctrl+Z steps back one batch at a time

How RoCode connects to Studio.

Questions

How do I make a spectate button in Roblox Studio?

In a LocalScript, set workspace.CurrentCamera.CameraSubject to another player's Humanoid when a button is clicked, and back to your own Humanoid to stop. Step 1 has the full script with next and previous.

How do I make the camera follow another player in Roblox?

Set camera.CameraSubject = otherPlayer.Character.Humanoid from a LocalScript. The default camera then orbits that character.

Why does my spectate camera break when the player dies?

Their Humanoid is replaced when they respawn. Connect to CharacterAdded on the watched player and set the subject to the new Humanoid.

Does spectating need a server script?

Not for the camera. A server script is only needed with StreamingEnabled, to set ReplicationFocus so the area around the watched player loads.

Can I spectate with a CameraType of Scriptable?

You can, but then you move the camera yourself every frame. Keeping the default Custom camera and only changing CameraSubject is much simpler.

Sources and further reading

How the code was checked: every script on this page passes Luau's strict type checker against Roblox's API definitions (luau-lsp, 14 November 2026). A type check catches misspelt APIs and wrong types, not game logic, so playtest in Studio before you publish.

Try RoCode on your own place.

Free every day, no card required. Install the plugin, describe the feature, and review what lands in Studio.