How to fix the "camera return to player" glitch and set the camera cframe to the head (without breaking it)

If you have been experiencing trouble with setting the camera subject or the camera cframe to any position and not been able to make it return to the player, here is the solution!
I found this out in a week of trying to fix my cutscene in which the CurrentCamera 's cframe was set to the characters head for smooth cutscenes, but this COMPLETELY broke the firstperson camera and broke movement and rotation and the orbital camera, but after a week of work i have finally figured it out! (this post was made because a bunch of people have asked how to fix this bug but with no reply) so here it is!

First make 2 Remote events in replicated storage to start and stop the cutscene.

Second you want to set the camera to the cframe of the head, a trigger for your cutscene will be good:
(also create all of the below inside of StarterGui (or PlayerGui) )

   --Simply trigger this remote to start the cutscene (localscript)
 game.ReplicatedStorage.Cutscene.OnClientEvent:Connect(function() --Start
 script.Parent.Looped.Value = true
 local camera = workspace.CurrentCamera
 player = game.Players.LocalPlayer.Name
 character = game.Workspace[player]
local part = character:WaitForChild("Head")
 camera.CameraSubject = part
 wait()
 camera.CFrame = part.CFrame
 end)

next you want to create a looped bool value (notice the script.Parent.Looped.Value Above)

then you want to create another localscript to exit the cutscene:

 game.ReplicatedStorage.Fix.OnClientEvent:Connect(function() --end the cutscene
local camera = workspace.CurrentCamera
 player = game.Players.LocalPlayer.Name
character = game.Workspace[player]
 local part = character:WaitForChild("Humanoid")
 camera.CameraSubject = part
 wait()
 script.Parent.Looped.Value = false
 end)

lastly you want to create a localscript to loop the cframe and exit the cframe

while true do
 	if script.Parent.Looped.Value == true then -- If the cutscene is on
 		local camera = workspace.CurrentCamera
 		player = game.Players.LocalPlayer.Name
 		character = game.Workspace[player]
 		local part = character:WaitForChild("Head")
		wait(0.1)
 		camera.CFrame = part.CFrame
 	else --If the Bool "Looped" is not true (aka if the cutscene is off)
		wait(0.4)
 		local camera = workspace.CurrentCamera
		player = game.Players.LocalPlayer.Name
 		character = game.Workspace[player]
 		local part = character:WaitForChild("Humanoid")
 		camera.CameraSubject = part
		wait(0.1)
 	end
 end

If this helped you let me know! if you have a more efficient method or issues then also let me know!
if your camera leaves first person when exiting the camera simply set StarterPlayer.CameraMode to LockFirstPerson or Player.CameraMode to LockFirstPerson! Have Fun!

2 Likes

I try to create a game without spawnlocation.

So when the server fire player.CharacterAdded:Connect(function(character)
i use a spawnplayer function to find a free virtual spawn part.

Then, i encountered problems with the PivotTo function which does not reposition the player’s camera.
So I was looking for a way to move the player’s camera when i use this function.

And the only solution i have found, is to use CameraEvent:FireClient(player)
and on the client, i wrote this

local player = game:GetService(“Players”).LocalPlayer
local hrp = player.Character:WaitForChild(“HumanoidRootPart”)

CameraEvent.OnClientEvent:Connect(function()
camera.CFrame = hrp.CFrame * CFrame.Angles(math.rad(-20),0,0) – i want the camera to be at this angle

end)

This solution works for me.
Is this normal that PivotTo do not do the job ( to teleport the player and set the camera back to him ) ?

sorry for the long wait! Please make sure you reply to me next time so i get it in my inbox.

have you tried to set the camera subject to the humanoid? (NOT the humanoidrootpart)


 local part = character:WaitForChild("Humanoid")
 camera.CameraSubject = part