How to make camera lean with the player?

Hi. I was wondering how to make the player lean, but keep the camera focused on the player? I tried using other scripts, but they don’t achieve the smooth effects that I wanted. I’m looking to implement it to this script, which makes the player bobble.

local char = game.Players.LocalPlayer.Character
local hrp = char.HumanoidRootPart
local cam = game.Workspace.Camera
local bobblex
local bobbley
local bobble

local other = coroutine.create(function()
	while game:GetService("RunService").Heartbeat:Wait() do
		if char.Humanoid.MoveDirection.Magnitude > 0 and char.Humanoid.FloorMaterial ~= Enum.Material.Air then
			--[[ this line doesnt work ]]-- cam.CFrame = cam.CFrame * CFrame.Angles(0,0, math.rad(45))
			
			char.Humanoid.CameraOffset = char.Humanoid.CameraOffset:lerp(bobble, .3)
		else
			char.Humanoid.CameraOffset = char.Humanoid.CameraOffset * .85
		end
		
		if char.Humanoid.WalkSpeed == 38 then
			bobblex = math.sin(tick() * 9) * 1
			bobbley = math.abs(math.sin(tick() * 10)) * 1.5
		else
			bobblex = math.sin(tick() * 6) * 1
			bobbley = math.abs(math.sin(tick() * 7)) * 1.5
		end
		bobble = Vector3.new(bobblex,bobbley,0)
	end
end)

coroutine.resume(other)

while game:GetService("RunService").Heartbeat:Wait() do
	if char.Humanoid.MoveDirection.Magnitude > 0 then
		repeat
			cam.FieldOfView += 1
			wait()
		until cam.FieldOfView > 80
		cam.FieldOfView = 80
	else
		repeat
			cam.FieldOfView -= 1
			wait()
		until cam.FieldOfView < 70
		cam.FieldOfView = 70
	end
end

Found a topic that CAN help (maybe not entirely)

It also includes a solution (credits to Forummer for it)

That one unfortunaely didnt work for me. The tween made my screen spin

What about only using their script? If you want to keep your FOV updates and such, you can try make it compatible instead of both running at once

ok. ill try thatㅤㅤㅤㅤㅤㅤㅤㅤㅤㅤㅤㅤㅤㅤㅤㅤㅤㅤㅤ

It works, but for mobile it doesnt. How do i fix that?

bump ㅤㅤㅤㅤㅤㅤㅤㅤㅤㅤㅤㅤㅤㅤㅤㅤㅤㅤㅤㅤㅤㅤㅤㅤㅤㅤㅤㅤㅤㅤㅤㅤㅤㅤㅤㅤ

You need to use some other functions for mobile since they dont use WASD / a keyboard