Camera stays put when you respawn

for some reason when I die, the currentcamera does not update to the new character when it respawns.
This is the code that sets the currentcamera cframe to a part in the workspace.

game.Players.LocalPlayer.CharacterAdded:Connect(function()
	currentcam.CameraType=Enum.CameraType.Scriptable
	currentcam.CFrame=maincam.CFrame
	
end)

I have seen similar posts like this before, but none of them were helpful.

2 Likes

You could bind the event when the character dies, the camera would return to its original type.

Something like this:

game.Players.LocalPlayer.CharacterAdded:Connect(function(character)
	currentcam.CameraType=Enum.CameraType.Scriptable
	currentcam.CFrame=maincam.CFrame

	character.Humanoid.Died:Connect(function()
		-- your code about the camera
	end)
end)

Do you know how to reset the camera to the player? Do I use cameraSubject?

I got one word: currentCam.CameraType = Enum.CameraType.Custom

Hey! First of all, make sure it’s not a server script. If you use CharacterAdded in a LocalScript, It wont detect your player joining because you character spawns before the localscript executes. I would either just fire a remoteEvent from the server to the client whenever the player joins/dies OR just remove the CharacterAdded function and add a wait() before changing the camera CFrame. The player’s camera won’t move, even when he dies.

LocalScript:

wait()
currentcam.CameraType = Enum.CameraType.Scriptable
currentcam.CFrame = maincam.CFrame
1 Like

Its a localscript. The characteradded event doesn’t work when I first join the game even though I added the wait() before it
Oh and by the way, I have another piece of code located in the same localscript that is supposed to fire when the player presses a button

button.MouseButton1Click:Connect(function()
	currentcam.CameraType=Enum.CameraType.Custom
	shopgui.Visible=false
	closeevent:FireServer()
	for i, v in pairs(script.Parent.Parent:GetChildren()) do
		v.Visible=false
	end
end)
1 Like

I don’t recommend using CharacterAdded in a LocalScript.

It shouldn’t be a problem if you have more code in the local script, just do this:

-- Changing the camera CFrame to maincam
wait()
currentcam.CameraType = Enum.CameraType.Scriptable
currentcam.CFrame = maincam.CFrame

-- CODE
button.MouseButton1Click:Connect(function()
	currentcam.CameraType=Enum.CameraType.Custom
	shopgui.Visible=false
	closeevent:FireServer()
	for i, v in pairs(script.Parent.Parent:GetChildren()) do
		v.Visible=false
	end
end)
1 Like

Tell me if it works. If it does, mark it as a solution :wink:

I used CharacterAppearanceLoaded instead, and it worked!

1 Like

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