First person lock on death

Hello,

I’m trying to make a script that forces the CurrentCamera to lock to the character’s head on death but it just sets the CFrame once. Here is the video:

aaaand a little section of the code:

script.Parent:WaitForChild("Humanoid").Died:Connect(function()
	camera.CameraType = Enum.CameraType.Scriptable
	
	repeat
		camera.CFrame = script.Parent:FindFirstChild("Head").CFrame
		wait(0.01)
		print("repeat")
	until game.Players.LocalPlayer.CharacterAdded

end)

Is there any better way to do such script? Any help would be appreciated.

of course, i just get ignored again

I didn’t understand what you want to achieve

excuse my bad english So, what I am trying to do is I want the camera to lock completely into the character’s head on death.

Simply, I want the camera’s cframe and orientation be exactly same with the characters head until they respawn.

Hope this is clear enough…

So like your script doesn’t work?

It just sets the position once then it stops working.

What position ignore

The CFrame and the orientation as seen in the video.

Sorry if I wasted your time, but I don’t know because I’m still a beginner

Is this a normal script or a localscript?

By the way, you don’t need a loop in order to set the CFrame.

It’s a localscript.

(this is the full code if necessary)

repeat wait	() until game:IsLoaded()

local camera = workspace.CurrentCamera

local function reset()

	repeat camera.CameraType = Enum.CameraType.Fixed until camera.CameraType == Enum.CameraType.Fixed
	
end

script.Parent:WaitForChild("Humanoid").Died:Connect(function()
	camera.CameraType = Enum.CameraType.Scriptable
	
	repeat
		camera.CFrame = script.Parent:FindFirstChild("Head").CFrame
		wait(0.01)
		print("repeat")
	until game.Players.LocalPlayer.CharacterAdded

end)

game.Players.LocalPlayer.CharacterAdded:Connect(function()
	reset()
	print("reset")
	
end)

1 Like

It’s okay, thanks for your time though.

local players = game:GetService("Players")
local player = players.LocalPlayer
local character = player.Character or player.CharacterAdded:Wait()
local humanoid = character:WaitForChild("Humanoid")
local head = character:WaitForChild("Head")
local camera = workspace.CurrentCamera
camera.CameraType = Enum.CameraType.Fixed

local function onHumanoidDied()
	camera.CameraType = Enum.CameraType.Scriptable
	camera.CFrame = head.CFrame
end

humanoid.Died:Connect(onHumanoidDied)

Local script inside StarterCharacterScripts, you may wish to swap the camera type when spawning from fixed to track (so the camera follows the player’s character).

the problem with your script is that game.Players.LocalPlayer.CharacterAdded will always be true because its an event
its like the script is repeating until the event exists

here’s my idea to fix it:

script.Parent:WaitForChild("Humanoid").Died:Connect(function()
	camera.CameraType = Enum.CameraType.Scriptable
	
	repeat
		camera.CFrame = script.Parent:FindFirstChild("Head").CFrame
		task.wait() --use task.wait cuz its more precise and syncs to heartbeat (optional)
		print("repeat")
	until game.Players.LocalPlayer.Character and game.Players.LocalPlayer.Character.Humanoid.Health > 0 --checks if player has a character, and if it does, checks if players character is alive

end)
1 Like

Oddly, that script just gave me a black screen…

Probably because you were setting the camera type to fixed (which locks the camera in place, in this case each time the player’s character spawns), I did suggest in my notes provided that you should set the camera type to track instead (as this is the default mode).

Thanks mate, much appreciated.