Camera not following player when leaning

  1. What do you want to achieve?
    I want to make a leaning system (like Rainbow Six Siege) that works flawlessly

  2. What is the issue?
    The actual leaning works but when the player leans, the camera does not follow the player (In the video I zoomed out so you can see the issue, the game will be in first person when it’s done)

  3. What solutions have you tried so far? Did you look for solutions on the Developer Hub?
    I tried all different things like using couroutine.wrap, the run service, custom camera types. I couldn’t find any existing solutions to this problem

This is my code so far:

local uis = game:GetService("UserInputService")
local tweenService = game:GetService("TweenService")
local rep = game:GetService("ReplicatedStorage")
local eventsFolder = rep:WaitForChild("Events")
local leaningEvent = eventsFolder:WaitForChild("Leaning")

local char = script.Parent
local hum = char:WaitForChild("Humanoid")

local camera = workspace.CurrentCamera

local ti = TweenInfo.new(
	0.5,
	Enum.EasingStyle.Sine
)

uis.InputBegan:Connect(function(key, isTyping)
	if key.KeyCode == Enum.KeyCode.E then
		camera.CameraType = Enum.CameraType.Scriptable
		leaningEvent:FireServer("Right") -- don't worry about this, this is just for making the head tilt on the server
		tweenService:Create(camera, ti, {CFrame = camera.CFrame * CFrame.Angles(0,0,math.rad(-35))}):Play()
	elseif key.KeyCode == Enum.KeyCode.Q then
		camera.CameraType = Enum.CameraType.Scriptable
		leaningEvent:FireServer("Left") -- don't worry about this, this is just for making the head tilt on the server
		tweenService:Create(camera, ti, {CFrame = camera.CFrame * CFrame.Angles(0,0,math.rad(35))}):Play()
	end
end)

uis.InputEnded:Connect(function(key)
	if key.KeyCode == Enum.KeyCode.E then
		leaningEvent:FireServer("Center", false) -- don't worry about this, this is just for making the head tilt on the server
		tweenService:Create(camera, ti, {CFrame = camera.CFrame * CFrame.Angles(0,0,math.rad(35))}):Play()
		wait(0.5)
		camera.CameraType = Enum.CameraType.Custom
	elseif key.KeyCode == Enum.KeyCode.Q then
		leaningEvent:FireServer("Center", false) -- don't worry about this, this is just for making the head tilt on the server
		tweenService:Create(camera, ti, {CFrame = camera.CFrame * CFrame.Angles(0,0,math.rad(-35))}):Play()
		wait(0.5)
		camera.CameraType = Enum.CameraType.Custom
	end
end)

I know making a leaning system that works the way I want it to is possible since I have seen games on Roblox have it, but after this, I really am confused on how they do it

{CFrame = camera.CFrame * CFrame.Angles(0,0,math.rad(-35))}

should instead be

{CFrame = game.Players.LocalPlayer.CFrame * CFrame.Angles(0,0,math.rad(-35))}

it didn’t work. And I know why. CFrame isn’t a valid member of the player. Thanks for trying to help tho

welp currently having the absolutely same issue, did u find out how to fix it? @LowLevelLegend

well I never ended up finding out how to fix it. I stopped trying to fix it a few days after posting this and decided to do it later on in development and instead work on more important gameplay mechanics. I find it funny that im replying to this after originally posting this 11 months ago lol

Shouldn’t you reference the player humanoidrootpart or is LocalPlayer enough?

I would do

{CFrame = game.Players.LocalPlayer.Character:WaitForChild("HumanoidRootPart").CFrame * CFrame.Angels(0, 0, math.rad(-35))}

funniest thing is that im currently trying to use the over-the-shoulder script from roblox on their camera manipulation page and its working sort of ok expect for the part when u unlean ur camera tps cuz of some angle conversion or whatever
https://gyazo.com/17e3e5e39ecb0c201e29fbd3ce1d9f53

all ive really changed since the original script is that its bound to the head instead of hrp but its still the same thing