When spectating a person and they die, it keeps spectating the person who has died

Hello, I’ve been trying to fix this issue where when the player dies, the spectating thing switches to the next person, or preferably keeps spectating the person who died. Right now, when the person you’re spectating dies, the camera position gets stuck in the position they’ve died at.

Spectating Script:

local bar = script.Parent.Bar
local title = bar.Title
local prev = bar.Previous
local nex = bar.Next
local button = script.Parent.Button

function get()
	for _,v in pairs(game.Players:GetPlayers())do
		if v.Name == title.Text then
			return(_)
		end
	end
end

local debounce = false
button.MouseButton1Click:connect(function()
	if debounce == false then debounce = true
		bar:TweenPosition(UDim2.new(.5,-100,0.88,-50),"In","Linear",1,true)
		pcall(function()
				title.Text = game.Players:GetPlayerFromCharacter(cam.CameraSubject.Parent).Name
		end)
	elseif debounce == true then debounce = false
		pcall(function() cam.CameraSubject = game.Players.LocalPlayer.Character.Humanoid end)
			bar:TweenPosition(UDim2.new(-1,-100,0.88,-50),"In","Linear",1,true)
		end
end)

prev.MouseButton1Click:connect(function()
	wait(.1)
	local players = game.Players:GetPlayers()
	local num = get()
	if not pcall(function() 
		cam.CameraSubject = players[num-1].Character.Humanoid
		end) then
		cam.CameraSubject = players[#players].Character.Humanoid
	end
pcall(function()
				title.Text = game.Players:GetPlayerFromCharacter(cam.CameraSubject.Parent).Name
		end)
end)

nex.MouseButton1Click:connect(function()
	wait(.1)
	local players = game.Players:GetPlayers()
	local num = get()
	if not pcall(function() 
		cam.CameraSubject = players[num+1].Character.Humanoid
		end) then
		cam.CameraSubject = players[1].Character.Humanoid
	end
pcall(function()
				title.Text = game.Players:GetPlayerFromCharacter(cam.CameraSubject.Parent).Name
		end)
end)
1 Like

Still having trouble finding a solution, I’ve looked all over the DevForum and the internet. (bump)

1 Like

Force the camera subject to change back to your own HumanoidRootPart after a set amount of seconds.

Make the set amount of seconds the RespawnTime.

2 Likes

you best best would be to check the humanoid health every so often of the target player. This means that should they die it can then stop them spectating that player.

while Spectating == true do
    if game.Players:GetPlayerFromCharacter(cam.CameraSubject.Parent).Humanoid.Health > 0 then
     --- Its All Good
    else
     wait(2) -- If they want to see the player die.
     --- Player Died, Stop / Change Spectate
    end
    wait(1)
end
1 Like

I did something like this:

while spectating == true do
	if game.Players:GetPlayerFromCharacter(cam.CameraSubject.Parent).Humanoid.Health > 0 then
		return
	else
		wait(2) 
		
		local players = game.Players:GetPlayers()
		local num = get()
		if not pcall(function() 
				cam.CameraSubject = players[num-1].Character.Humanoid
			end) then
			cam.CameraSubject = players[#players].Character.Humanoid
		end
		pcall(function()
			title.Text = game.Players:GetPlayerFromCharacter(cam.CameraSubject.Parent).Name
		end)
	end
	wait(1)
end

However, it still won’t work.

you need to set spectating. the while loop should be within your other code. so it shouldn’t be the main bit.

1 Like