DeathJumpscare script not orking

Hi all
I am making a Horror game in which i made a script that when a player dies the camera shifts to the antagonist
but for some reason that is not workin and i cant identify the problem!

Here’s the script

local players = game.Players
local cam = game.Workspace.CurrentCamera

game:GetService('Players').PlayerAdded:Connect(function(player)
	player.CharacterAdded:Connect(function(character)
		character:WaitForChild("Humanoid").Died:Connect(function()

			local pos = Vector3.new(-1449.6, 10.6, 11)
			local LookAt = Vector3.new(0, -90, 0)
			local CameraCFrame = CFrame.new(pos, LookAt) 
			cam.CameraType = Enum.CameraType.Scriptable
			cam.CFrame = CameraCFrame		

		end)
	end)
end)
1 Like

Hi, if you’re running this on a LocalScript it might be because PlayerAdded is not being fired as the client initialises after the creation of the player. Is the script a LocalScript or regular Script?

it is a server script (so that roblox lets me reply)

Do it in a LocalScript, since camera manipulation can only be done in Client, not server.
More information about Camera Manipulation: Camera Manipulation

local cam = game.Workspace.CurrentCamera
	game.Players.LocalPlayer.CharacterAdded:Connect(function(character)
		character:WaitForChild("Humanoid").Died:Connect(function()

			local pos = Vector3.new(-1449.6, 10.6, 11)
			local LookAt = Vector3.new(0, -90, 0)
			local CameraCFrame = CFrame.new(pos, LookAt) 
			cam.CameraType = Enum.CameraType.Scriptable
			cam.CFrame = CameraCFrame		

		end)
	end)

Try this

local players = game.Players
local player = players.LocalPlayer
local character = player.Character or player.CharacterAdded:Wait()
local humanoid = character:WaitForChild("Humanoid")

local camera = workspace.CurrentCamera

humanoid.Died:Connect(function()
	camera.CameraType = Enum.CameraType.Scriptable
	camera.CFrame = CFrame.lookAt(Vector3.new(-1450, 11, 11), Vector3.new(0, -90, 0))
end)

Local script.

psst this’ll only work for the first time the character spawns

Because the character variable parameter was destroyed, you have to connect the player.CharacterAdded function to make it work again.

local players = game.Players
local player = players.LocalPlayer
local character = player.Character
local humanoid = character:WaitForChild("Humanoid")

local camera = workspace.CurrentCamera

local function myFunction()
    camera.CameraType = Enum.CameraType.Scriptable
	camera.CFrame = CFrame.lookAt(Vector3.new(-1450, 11, 11), Vector3.new(0, -90, 0))
end

humanoid.Died:Connect(myFunction)

player.CharacterAdded:Connect(function(Character)
    local humanoid = Character:WaitForChild("Humanoid")
    humanoid.Died:Connect(myFunction)
end)

Nah, just place it inside “StarterCharacterScripts” if you need it to execute each time the player’s character respawns/reloads etc.