Fixing my spectate feature

I made a simple spectate UI, how it works is when the player open the spectate window they have a next button and everytime they press it, it shows them the character of a different player they can spectate. This script is in a local script. The issue is that when a player dies if anyone is spectating them the camera will get stuck where they died and doesn’t respawn when the player respawns, it just stays in the spot they died. I tried to make a variable called “SpecPlr” and when that player dies, the camera switches to the new character spawn. The issue here was that from a local script you can’t get information if a different player dies so the event wasn’t even able to run.

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

my solution would be,
make an event for when a player dies,

server:

local Event --path to event
game:GetService("Players").PlayerAdded:Connect(function(player)
player.CharacterAdded:Connect(function(character)
character:WaitForChild("Humanoid").Died:Connect(function()
Event:FireClient(player)
end)
end)
end)

Client:

local event -- path to it
event.OnClientEvent:Connect(function()
--reset the camera, add this to the local script
end)


1 Like

I thought of this but do you think that this would cause too much lag because I am making an obby game with 25 players in one server who will be constantly dying.

Well, the reason i think the camera is locking is because you only connect the function once the button is clicked.

I don’t think it will lag, but I think you Can try and test around and see does it lag , if you want, It should not tho the servers can easily handle a ton of death events

it’s the constant remote events im worried about not the death events.

I don’t know any smarter or more efficient way at the moment , But I Don’t think its a problem. I suggest you use the remote event method unless you find a better way :grinning: