Help with camera bobbing

Hi, I wanted to make a camera that bobbles when you walk in first person. The script works, the problem is that when WalkSpeed ​​is = 0 and you try to walk, the camera still bobbles (which it shouldn’t). I don’t know what to do.

This is the script:

local RunService = game:GetService("RunService")
 
local playerModel = script.Parent
local humanoid = playerModel:WaitForChild("Humanoid")
 
local function updateBobbleEffect()
	local now = tick()
	if humanoid.MoveDirection.Magnitude > 0 then
		local velocity = humanoid.RootPart.Velocity
		local bobble_X = math.cos(now * 9) / 5
		local bobble_Y = math.abs(math.sin(now * 12)) / 5
		
		local bobble = Vector3.new(bobble_X,bobble_Y,0) * math.min(1, velocity.Magnitude / humanoid.WalkSpeed)
		humanoid.CameraOffset = humanoid.CameraOffset:lerp(bobble,.25)
	else
		humanoid.CameraOffset = humanoid.CameraOffset * 0.75
	end
end

RunService.RenderStepped:Connect(updateBobbleEffect)