Over the Sholder Shift Lock Character Issue

Hi all!
I’m having an issue with a game I’ve been working on.
I am terrible with Camera Manipulation, so I used HowToRoblox’s “Over the Shoulder” video to create a shift lock type of camera. However, the issue is that the player can run into a wall and rotate their character, and once they leave the wall they are stuck in that rotation (see video below).

Video: CameraProblem

Script:
local uis = game:GetService("UserInputService")

local shift = true
local camera = workspace.CurrentCamera
camera.CameraType = Enum.CameraType.Scriptable


local char = script.Parent

local humanoid = char:WaitForChild("Humanoid")
humanoid.AutoRotate = false

local hrp = char:WaitForChild("HumanoidRootPart")


local x = 0
local y = 0


local offset = Vector3.new(3, 3, 10)


uis.InputChanged:Connect(function(input, processed)
	
	if processed then return end
	
	if input.UserInputType == Enum.UserInputType.MouseMovement then
		
		x = x - input.Delta.X
		
		y = math.clamp(y - input.Delta.Y*0.4, -75, 75)
		
		
		hrp.CFrame = hrp.CFrame * CFrame.Angles(0, math.rad(-input.Delta.X), 0)
	end
end)


game:GetService("RunService").RenderStepped:Connect(function()
	if shift then
	
		uis.MouseIconEnabled = false
		
		uis.MouseBehavior = Enum.MouseBehavior.LockCenter
		
		
		local startCFrame = CFrame.new((hrp.CFrame.Position)) * CFrame.Angles(0, math.rad(x), 0) * CFrame.Angles(math.rad(y), 0, 0)
		local cameraCFrame = startCFrame:ToWorldSpace(CFrame.new(offset.X, offset.Y, offset.Z))
		local cameraDirection = startCFrame:ToWorldSpace(CFrame.new(offset.X, offset.Y, -10000))
	
		camera.CFrame = CFrame.new(cameraCFrame.Position, cameraDirection.Position)
	else
		uis.MouseIconEnabled = true

		uis.MouseBehavior = Enum.MouseBehavior.Default
	end
end)

game.ReplicatedStorage.ShiftLock.OnClientEvent:Connect(function(shiftRem)
	if shiftRem == true then
		shift = true
	else 
		shift = false
	end
end)

I need the player’s character to always be facing in the direction that the camera is facing, anyone have any ideas? Any help is appreciated!