Camera not following the player

So i made a script that changes your CFrame of the Camera to players head, is there any way i can make it follow the players head.

Here is the script:

local plr = game.Players.LocalPlayer

local Camera = game.Workspace.CurrentCamera -- Getting the Camera
local player = game.Players.LocalPlayer 

game:GetService("UserInputService").InputBegan:Connect(function(input)
	if input.KeyCode == Enum.KeyCode.F then
		repeat wait() until player.Character
		Camera.CameraType = "Scriptable"
		Camera.CFrame = player.Character.Head.CFrame
		Camera.CameraSubject = player.Character.Head
		
	end
end)
2 Likes

Yes, set Camera.CameraSubject to the player’s Humanoid (or head).

1 Like

but i already did that. i set the camerasubject to the players head

1 Like

So you want the camera to go in first-person mode when we press F?

Not actually First Person, But the cameras position to be in the players head and follow the head or any other body part

Try setting the CameraType to Custom

Okay, I found the problem! Here is my code, hope it helps all I did was change the mode to track and make CameraMaxZoomDistance to 0

local plr = game.Players.LocalPlayer

local Camera = game.Workspace.CurrentCamera -- Getting the Camera
local player = game.Players.LocalPlayer 

game:GetService("UserInputService").InputBegan:Connect(function(input)
	if input.KeyCode == Enum.KeyCode.F then
		repeat wait() until player.Character
		plr.CameraMaxZoomDistance = 0
		Camera.CameraType = Enum.CameraType.Attach
		Camera.CFrame = player.Character.Head.CFrame
		Camera.CameraSubject = player.Character.Head
	end
end)
2 Likes

yoo it worked tsym. Also is there anyway i can reset all the settings to normal if the F is key pressed again, i tried using inputended but it didnt work.

There are many modes you can choose from like follow, Track, Attach which also looks good.

This should work.

local plr = game.Players.LocalPlayer

local Camera = game.Workspace.CurrentCamera -- Getting the Camera
local player = game.Players.LocalPlayer 
isin = false
game:GetService("UserInputService").InputBegan:Connect(function(input)
	if input.KeyCode == Enum.KeyCode.F then
		if isin == false then
			print("Yes")
			isin = true
			repeat wait() until player.Character
			plr.CameraMaxZoomDistance = 0
			Camera.CameraType = Enum.CameraType.Attach
			Camera.CFrame = player.Character.Head.CFrame
			Camera.CameraSubject = player.Character.Head
		else
			print("No")
			Camera.CameraType = Enum.CameraType.Custom
			plr.CameraMaxZoomDistance = 50
			Camera.CFrame = plr.Character.HumanoidRootPart.CFrame
			Camera.CameraSubject = plr.Character.Humanoid
			isin = false
		end
	end
end)

Don’t worry about print statements and other variables there just for testing,