Help with Camera locking to head

I’m having an issue making the camera position based off the character’s head, but also make it freely move around.

However whenever I run the game and go into first person, it spins like a fidget spinner.

Doors game bug

--Setup--

--Services--
local Plrs = game:GetService("Players")

local RS = game:GetService("ReplicatedStorage")

local RS2 = game:GetService("RunService")

--Player--
local Plr = Plrs.LocalPlayer

local GUI = Plr.PlayerGui

--Remotes--
local Remotes = RS:WaitForChild("Remotes")

--Camera--
local Cam = workspace.CurrentCamera

---------

--Main Code--

repeat wait() until Plr.Character

RS2.RenderStepped:Connect(function()
	if Plr.Character then
		local Distance = (Plr.Character.Head.Position - Cam.CFrame.Position).Magnitude
		if Distance <= 10 then
			
			Cam.CFrame = CFrame.new(Plr.Character.Head.Position.X, Plr.Character.Head.Position.Y, Plr.Character.Head.Position.Z)
			
			for i, v in pairs(Plr.Character:GetDescendants()) do
				if v:IsA("BasePart") and v.Name ~= "Head" then
					
					v.LocalTransparencyModifier = 0
					
				if v.Parent:IsA("Accessory") and v.Name == "Handle" then
					
					v.LocalTransparencyModifier = 1
				end
				
				end
			end
			
		end
	end
end)

-------------

The code above is my entire script for handling the camera. And don’t worry about the range. The player will always be in First Person Lock when I’m finished with the game.

Is it spinning in circles, or behaving oddly while moving it?

You may be running into a gimbal lock issue with CFraming, where the CFrame rotates it 90 degrees and the axes align.
Search gimbal lock on the forums to see some good answers about how to fix it.

1 Like

It is spinning in circles, but only when I go into first person, moving my camera unfortunately does not move my character.

Alright I’ll let you know if I find anything!

Edit: Need help on locking camera look direction to player head - #15 by xXSanrioSlayer99

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