How to make a spectate camera follow a camera after death

I added a spectate feature to my game however whenever the player that the camera is follow dies the camera doesn’t reset with the character so it is just stuck in one spot where the character was right before they died.

local camera = game.Workspace.CurrentCamera
local number = 1
local plr = game.Players.LocalPlayer
local Players = game.Players:GetPlayers()

script.Parent.Next.MouseButton1Up:Connect(function()
	number = number + 1
	if Players[number] ~= nil then
		camera.CameraSubject = Players[number].Character.Humanoid
		script.Parent.Player.Text = Players[number].Name
	end
	if Players[number] == nil then
		number = 1
		camera.CameraSubject = Players[number].Character.Humanoid
		script.Parent.Player.Text = Players[number].Name
	end
end)

This is what I have so far.

1 Like

Use the :MouseButton1Click() instead.

That isn’t really the issue. The issue is that once a player dies the camera stops following them.

You could check when the spectated player’s character is added again (Player.CharacterAdded) and change the camera subject to the new character. Disconnect the function when the spectator is changed