Camera subject will not change when expected

Hello.
I am trying to script something in the local script where, if a survivor dies from the killer, the survivors camera subject immeadiately towards the killers humanoid.
I’ve tried looking on the forums and trying to fix it myself, but there is no output and I couldn’t find any solution.
Here is my code.

local player = game:GetService("Players").LocalPlayer
local replicatedStorage = game:GetService("ReplicatedStorage")
local roundend = replicatedStorage:WaitForChild("RoundEnd", 10)
if not roundend then return end
local camera = workspace.CurrentCamera

local function onCharacterAdded(character)
	local humanoid = character:WaitForChild("Humanoid", 10)
	if not humanoid then
		return
	end
	humanoid.Died:Connect(function()
		local Entity = workspace.EntityFolder:WaitForChild("Entity")
		if Entity then
			camera.CameraType = Enum.CameraType.Follow
			camera.CameraSubject = Entity
		else
		end
	end)
end

roundend.OnClientEvent:Connect(function()
	camera.CameraType = Enum.CameraType.Custom
end)

Any help is appreciated. Thank you.

I’ve fixed it.

local function onCharacterAdded(character)

this was dragging the whole script behind because I didn’t really define what onCharacterAdded was. So I just removed it.

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.