Why does the camera stay on the dead body?

The camera mode is LockedFirstPerson

You may need to add code to detect when the player dies and respawn them with a new camera.

-- Get the player's character
local character = game.Players.LocalPlayer.Character

-- Connect to the character's "Died" event
character.Humanoid.Died:Connect(function()

	-- Wait for the player to respawn
	wait(5) -- Change this to however long it takes for the player to respawn in your game
	
	-- Get the player's new character
	local newCharacter = game.Players.LocalPlayer.Character or game.Players.LocalPlayer.CharacterAdded:Wait()
	
	-- Get the new character's humanoid and wait for it to load
	local humanoid = newCharacter:WaitForChild("Humanoid")
	humanoid:WaitForChild("RootPart")
	
	-- Set the camera to the new character's head
	local camera = workspace.CurrentCamera
	camera.CameraType = Enum.CameraType.Custom
	camera.CFrame = CFrame.new(newCharacter.Head.Position + Vector3.new(0, 0.5, 0), newCharacter.Head.Position)
	wait(0.1)
	camera.CameraType = Enum.CameraType.LockedFirstPerson
	
end)

doesn’t seem to do anything hmm

wait it seems none of my character related scripts work after resetting, such as sprinting and flashlight

Could you kindly provide the script that is causing this issue?
This will enable us to accurately identify the problem and resolve it.

I don’t know what script is causing the issue.
Best I can give are these 3 scripts that don’t work after resetting. The first is in StarterGui, the second in starterplayerscripts and the 3rd in startercharacter scripts
1:

local function playClick()
	
	local startVol = game.SoundService.menuMusic.Volume
	
	local darken = script.Parent.Parent.Parent.darkener.darken
	
	game.Players.LocalPlayer.PlayerGui.Menu.Enabled = false
	
	local userInputService = game:GetService("UserInputService")
	
	local guideTxt = game.Players.LocalPlayer.PlayerGui.guide1.text

	userInputService.MouseIconEnabled = false
	
	while darken.Transparency >= 0 do
		wait(0.01)
		darken.Transparency -= 0.02
		game.SoundService.menuMusic.Volume -= (startVol/100)*2
	end
	
	--gameplay settings
	plr.Humanoid:RemoveAccessories()
	game.Lighting.Atmosphere.Density = 0.9
	game.Lighting.Brightness = 0.75
	plr:MoveTo(workspace.startBlock.Position)
	camCheck = true
	wait(0.1)
	game.Players.LocalPlayer.CameraMode = Enum.CameraMode.LockFirstPerson
	wait(0.5)
	game.SoundService.wind.Playing = true
	
	--enable scripts
	game.Players.LocalPlayer.PlayerScripts.ambience1.Disabled = false
	game.Players.LocalPlayer.PlayerScripts.ambience2.Disabled = false
	game.Players.LocalPlayer.PlayerScripts.ambience3.Disabled = false
	game.Players.LocalPlayer.PlayerScripts.ambience4.Disabled = false
	game.Players.LocalPlayer.PlayerScripts.flashlight.Disabled = false
	game.Players.LocalPlayer.PlayerScripts.walkSounds.Disabled = false
	game.Players.LocalPlayer.Character.sprint2.Disabled = false
	game.Players.LocalPlayer.Character.bobble.Disabled = false
	game.Players.LocalPlayer.PlayerGui.Interface.bg.Visible = true
	
	while darken.Transparency <= 1 do
		wait(0.01)
		darken.Transparency += 0.02
	end	

	while guideTxt.TextTransparency > 0 do
		wait(0.01)
		guideTxt.TextTransparency -= 0.02
		guideTxt.UIStroke.Transparency -= 0.02
	end
	
	wait(5)
	while guideTxt.TextTransparency < 1 do
		wait(0.01)
		guideTxt.TextTransparency += 0.02
		guideTxt.UIStroke.Transparency += 0.02
	end
end	

2:

-- variables

local char = game.Players.LocalPlayer.Character or game.Players.LocalPlayer.CharacterAdded:Wait()
local light = Instance.new("SpotLight")
light.Parent = char:WaitForChild("Head")
light.Brightness = 0
light.Range = 20
light.Angle = 30
lightOn = false
clickRed = false

local uis = game:GetService("UserInputService")

--functions

uis.InputBegan:Connect(function(input)
	
	if input.UserInputType == Enum.UserInputType.MouseButton1 then
		
		if lightOn == false then
			light.Brightness = 10
				wait(2)
				lightOn = true
						
		elseif lightOn == true then
			light.Brightness = 0
				wait(2)
				lightOn = false
					
		end
	end
end)

uis.InputBegan:Connect(function(input)

	if input.UserInputType == Enum.UserInputType.MouseButton1 then

		if clickRed == false then
			game.SoundService.clickSound2:Play()
			clickRed = true
			wait(2)
			clickRed = false
		end
	end
end)

3:

local char = script.Parent
local humanoid = char:WaitForChild("Humanoid")
local plr = game.Players.LocalPlayer

local sprintKey = Enum.KeyCode.LeftShift

local uis = game:GetService("UserInputService")

local maxStamina = 100
local stamina = maxStamina

local sprinting
local sprintSpeed = 12
local regularSpeed = 7

function startSprint()
	sprinting = true
end

function stopSprint()
	sprinting = false
end

function checkKey(key, isTyping, doSprint)
	local player = game:GetService("Players").LocalPlayer
	local character = player.Character or player.CharacterAdded:Wait()
	local humanoid = character:WaitForChild("Humanoid")
	if not isTyping then
		if key.KeyCode == sprintKey then
			if doSprint then
				startSprint()
				if humanoid.FloorMaterial == Enum.Material.Wood or humanoid.FloorMaterial == Enum.Material.Cobblestone then
					game.SoundService.grass.PlaybackSpeed = 1.15
				elseif humanoid.FloorMaterial == Enum.Material.Grass then
					game.SoundService.grass.PlaybackSpeed = 2.25
				else	
					game.SoundService.grass.PlaybackSpeed = 1
				end
			else
				stopSprint()
				if humanoid.FloorMaterial == Enum.Material.Wood or humanoid.FloorMaterial == Enum.Material.Cobblestone then
					humanoid.WalkSpeed = 11
					game.SoundService.grass.PlaybackSpeed = 1.05
					wait(0.05)
					humanoid.WalkSpeed = 10
					game.SoundService.grass.PlaybackSpeed = 0.95
					wait(0.05)
					humanoid.WalkSpeed = 9
					game.SoundService.grass.PlaybackSpeed = 0.90
					wait(0.05)
					humanoid.WalkSpeed = 8
					game.SoundService.grass.PlaybackSpeed = 0.85
					wait(0.05)
					humanoid.WalkSpeed = 7.5
					game.SoundService.grass.PlaybackSpeed = 0.80
					wait(0.05)
					humanoid.WalkSpeed = 7
					game.SoundService.grass.PlaybackSpeed = 0.75
				elseif humanoid.FloorMaterial == Enum.Material.Grass or humanoid.FloorMaterial == Enum.Material.LeafyGrass then
					humanoid.WalkSpeed = 11
					game.SoundService.grass.PlaybackSpeed = 2.15
					wait(0.05)
					humanoid.WalkSpeed = 10
					game.SoundService.grass.PlaybackSpeed = 2
					wait(0.05)
					humanoid.WalkSpeed = 9
					game.SoundService.grass.PlaybackSpeed = 1.85
					wait(0.05)
					humanoid.WalkSpeed = 8
					game.SoundService.grass.PlaybackSpeed = 1.75
					wait(0.05)
					humanoid.WalkSpeed = 7.5
					game.SoundService.grass.PlaybackSpeed = 1.6
					wait(0.05)
					humanoid.WalkSpeed = 7
					game.SoundService.grass.PlaybackSpeed = 1.5
				else
					humanoid.WalkSpeed = 11
					game.SoundService.grass.PlaybackSpeed = 0.95
					wait(0.05)
					humanoid.WalkSpeed = 10
					game.SoundService.grass.PlaybackSpeed = 0.9
					wait(0.05)
					humanoid.WalkSpeed = 9
					game.SoundService.grass.PlaybackSpeed = 0.85
					wait(0.05)
					humanoid.WalkSpeed = 8
					game.SoundService.grass.PlaybackSpeed = 0.8
					wait(0.05)
					humanoid.WalkSpeed = 7.5
					game.SoundService.grass.PlaybackSpeed = 0.75
					wait(0.05)
					humanoid.WalkSpeed = 7
					game.SoundService.grass.PlaybackSpeed = 0.6
				end
			end
		end
	end
end

uis.InputBegan:Connect(function(key, isTyping)
	checkKey(key, isTyping, true)
end)

uis.InputEnded:Connect(function(key, isTyping)
	checkKey(key, isTyping, false)
end)

while wait() do
	if sprinting then
		if stamina > 0 then
			stamina -= 0.8
			humanoid.WalkSpeed = sprintSpeed
		else
			humanoid.WalkSpeed = regularSpeed
			game.SoundService.grass.PlaybackSpeed = 0.6
		end
	else
		if stamina < maxStamina then
			stamina += 0.15
		end
		humanoid.WalkSpeed = regularSpeed
	end
	plr.PlayerGui.Interface.bg:TweenSize(UDim2.new(stamina / maxStamina, 0, 1, 0), Enum.EasingDirection.In, Enum.EasingStyle.Linear, 0)
end

Unfortunately, the three scripts you provided don’t seem to have anything to do with the camera or dead bodies.

well, that is why I’m confused. I even tried to disable most of the scripts and it didn’t change anything.

Start putting lines like print("whatever variable = ",the variable) in your code to see what scripts are and aren’t firing and why. This will help your troubleshooting immensely.
Something like:

	if not isTyping then
        print("KeyCode = ", KeyCode, "    sprintKey = ", sprintKey)  --this will let you know where the print is located in your Output window and what the values are.
		if key.KeyCode == sprintKey then
1 Like

how does this help exactly? I wrote it and it is printing nothing after respawning (as expected)
I understand that is is general advice ofc

But it tells you those variable values haven’t been set, so you know that whatever is setting them is not working.
Then you go to the section of code that sets the variable values and do the same thing with values in that code.
Keep tracing back until you get good values and you can see exactly the break in the chain so you can concentrate there, rather than just saying ‘here’s the 3 sections of code that don’t work’. This lets you go back to the scripts that sets those values so you can get the proper ones.

This helps to trace back to the cause(s) of the problem and not just focus on the end result.

1 Like

You should simply set the workspace.CurrentCamera.CameraType to fixed when the player dies. If that doesnt work, then along with it set the camera mode to classic and reset both things when the player respawns.

1 Like

alright will try that tommorow

1 Like

I wrote this and it didn’t work. Is the code correct?

game.Players.LocalPlayer.Character:WaitForChild("Humanoid").Died:Connect(function()
	workspace.CurrentCamera.CameraType = Enum.CameraType.Fixed
	game.Players.LocalPlayer.CameraMode = Enum.CameraMode.Classic
	wait(5)
	workspace.CurrentCamera.CameraType = Enum.CameraType.Scriptable
	game.Players.LocalPlayer.CameraMode = Enum.CameraMode.LockFirstPerson
end)

wrap all this in task.Spawn

game.Players.LocalPlayer.Character:WaitForChild("Humanoid").Died:Connect(function()
    task.spawn(function()
      	workspace.CurrentCamera.CameraType = Enum.CameraType.Fixed
        game.Players.LocalPlayer.CameraMode = Enum.CameraMode.Classic
        wait(5)
        workspace.CurrentCamera.CameraType = Enum.CameraType.Scriptable
        game.Players.LocalPlayer.CameraMode = Enum.CameraMode.LockFirstPerson
    end)
end)

doesn’t seem to make a difference
I told it to print and it seems to only print the part before the wait(5)
image
image

then you could maybe do this.

game.Players.LocalPlayer.Character:WaitForChild("Humanoid").Died:Connect(function()
    task.spawn(function()
      	workspace.CurrentCamera.CameraType = Enum.CameraType.Fixed
        game.Players.LocalPlayer.CameraMode = Enum.CameraMode.Classic
    end)
    task.wait(5)
    task.spawn(function()
        workspace.CurrentCamera.CameraType = Enum.CameraType.Scriptable
        game.Players.LocalPlayer.CameraMode = Enum.CameraMode.LockFirstPerson
    end)
end)

same result.
Isn’t it weird that it doesn’t even print “nil” or gives an error?
The problem seems to lie there.

I checked further, and it’s like something is permantly connecting the camera to my head.CFrame on presumably every frame or so, even after disabling all camera related scripts.

Maybe you could set camera subject to nil and head whenever needed in the above code?