I Wanna Reset The Camera When You Die

I been trying to make a horror game and i cant get this work when you die the camera dont reset after 5 seconds

local player = game.Players.LocalPlayer
local humanoid = player.Character.Humanoid
local Camera = game.Workspace.CurrentCamera
local campart = game.Workspace.Cameras.DeathCam

function StartJumpscare()
Camera.CameraType = Enum.CameraType.Scriptable
Camera.CFrame = campart.CFrame
warn(“Test”)
script.LocalScript.Enabled = true
end

function GUIShow()
script.Parent.Parent.Parent.DeathScreen.Enabled = true
end

while true do
task.wait(0.1)
if humanoid.Health == 0 then
StartJumpscare()
wait(5)
Camera.CameraType = Enum.CameraType.Custom
end
end

you should just set properties of camera as they were before

1 Like

LocalScripts in the character model will refresh after dying. You can most likely fix this by adding the following:

...
local Camera = game.Workspace.CurrentCamera
local campart = game.Workspace.Cameras.DeathCam

Camera.CameraType = Enum.CameraType.Custom
...

This should revert the camera back into its original properties after respawning.


I also suggest changing your last while .. do loop to be more effecient by connecting it to the Humanoid.Died event.

humanoid.Died:Connect(StartJumpscare)
1 Like

When testing in studio, the issue seems to be that the CameraSubject property of the Camera does not get set to the new humanoid of the respawned character.

Usually this is automatic, but when the camera is in scriptable mode this seems to not happen.

So, the solution I found was to find the characters humanoid again when the player spawns and set the Camera’s CameraSubject Property to the new humanoid.

Here’s my example:
Edit: Removed unnecessary lines of code I forgot to remove after testing

local player = game.Players.LocalPlayer
local Camera = game.Workspace.CurrentCamera
local campart = game.Workspace.Cameras.DeathCam

function StartJumpscare()
	Camera.CameraType = Enum.CameraType.Scriptable
	Camera.CFrame = campart.CFrame
	warn("Test")
end

function ResetCamera(humanoid : Humanoid)
	Camera.CameraType = Enum.CameraType.Custom
	Camera.CameraSubject = humanoid
end

function GUIShow()
	script.Parent.Parent.Parent.DeathScreen.Enabled = true
end

player.CharacterAdded:Connect(function(character : Model)
	local humanoid : Humanoid = character:WaitForChild("Humanoid")
	ResetCamera(humanoid)
	humanoid.Died:Once(StartJumpscare)
end)
1 Like

did not work Thats Looks like chatgpt

1 Like

I literally just wrote it by hand.

And it works on my system, but maybe there is something different about your game environment.

Sorry to hear it didn’t work.

1 Like

it says DeathCam is not a valid member of Folder “Workspace.Cameras”
but it is in the folder

1 Like

use

local campart = game.Workspace.Cameras:FindFirstChild("DeathCam")

instead of

local campart = game.Workspace.Cameras.DeathCam

and make sure that the name is right because there could be an spelling mistake

and im right next to it so i dont know why

1 Like

replace the above line with this:

local campart = game.Workspace.Cameras:WaitForChild("DeathCam")

This should make sure the code waits for the part to actually exist before continuing.

The only other thing I can think of is maybe StreamingEnabled is set to true.

i write a hole new script
wait(2)
local player = game.Players.LocalPlayer
local Camera = game.Workspace.CurrentCamera
local campart = game.Workspace.Cameras:FindFirstChild(“DeathCam”)

function StartJumpscare()
Camera.CameraType = Enum.CameraType.Scriptable
Camera.CFrame = campart.CFrame
warn(“Test”)
end

function ResetCamera()
Camera.CameraType = Enum.CameraType.Custom
Camera.CameraSubject = player.Character.Humanoid
end

player.Character.Humanoid.Died:Connect(function()
StartJumpscare()
wait(5)
Camera.CameraType = Enum.CameraType.Custom
Camera.CameraSubject = player.Character.Humanoid
end)

The problem is, this will refresh under the character every time it dies. I’d recommend putting it in “StarterPlayerScripts” and slightly modify the script.

1 Like

thank you So Much Now I Can Continue My Game

1 Like

if he did answered your question then you need to mark him as a solution.

hey dude i just noticed it dont work 2nd time only works 1st time (Just Scare Does Not Trigger On 2nd death)

hi

your problem is that the script only checks if the players first character dies, not the characters that spawn afterwards

to help explain, this is what happens when the player joins the game (in a nutshell):
  1. your player joins the game
  2. the players character loads in
  3. the script firstly defines the players character as a variable, lets simply call it “Character
  4. that players character dies, so the .Died event is triggered
  5. the jumpscare happens and the players has a completely new character created
  6. the Character variable is still set to the original character, that died
  7. the new character dies, but the .Died event is only checking for the Character variable dying, so no jumpscare is fired.
  8. all is sad

to fix this, you can check when the original character dies, trigger the jumpscare, and then start checking if the new character dies, so on, so on.

heres your modified script:

local player = game.Players.LocalPlayer
local Character = player.Character or player.CharacterAdded:Wait() -- waits for the character to be added to the workspace

local deathConnection : RBXScriptConnection

local Camera = game.Workspace.CurrentCamera
local campart = game.Workspace.Cameras:WaitForChild("DeathCam")

local RESPAWN_TIME = 5

function StartJumpscare()
	Camera.CameraType = Enum.CameraType.Scriptable
	Camera.CFrame = campart.CFrame
	warn("Test")
end

function ResetCamera()
	Camera.CameraType = Enum.CameraType.Custom
	Camera.CameraSubject = player.Character.Humanoid
end

function Jumpscare() -- a new function that is fired whenever the character dies
	deathConnection:Disconnect() -- stop listening for the old character to die, for performance
	StartJumpscare()
	wait(RESPAWN_TIME)
	ResetCamera()
	Character = player.Character or player.CharacterAdded:Wait() -- waits for the character to be added to the workspace
	Character:WaitForChild("Humanoid").Died:Connect(Jumpscare)
end


deathConnection = Character:WaitForChild("Humanoid").Died:Connect(Jumpscare)

ive also removed the wait(2) the top of your script

if you want me to go over anything (i probably did a horrible job explaining why it wasnt working), let me know

here very lazy fix but works (without connections so this is very unoptimized)

local player = game:GetService("Players").LocalPlayer
local Camera = workspace.CurrentCamera
local campart = workspace:WaitForChild("Cameras"):WaitForChild("DeathCam")

function StartJumpscare()
	Camera.CameraType = Enum.CameraType.Scriptable
	Camera.CFrame = campart.CFrame
	script.LocalScript.Enabled = true
end

function GUIShow()
	script.Parent.Parent.Parent.DeathScreen.Enabled = true
end

while true do
	if player.Character and player.Character:FindFirstChildOfClass("Humanoid") and player.Character:FindFirstChildOfClass("Humanoid").Health==0 then
		StartJumpscare()
		task.wait(5)
		Camera.CameraType = Enum.CameraType.Custom
	end
	task.wait()
end

never mind i fixed it all thanks guys for the help :smiley:

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