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
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)
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
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.
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):
your player joins the game
the players character loads in
the script firstly defines the players character as a variable, lets simply call it “Character”
that players character dies, so the .Died event is triggered
the jumpscare happens and the players has a completely new character created
the Character variable is still set to the original character, that died
the new character dies, but the .Died event is only checking for the Character variable dying, so no jumpscare is fired.
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