Viewmodel bobbing working wrong

My bobbing working, but only if player idle, if player walking then bobbing don’t work(if i stupid my fault)
Code:

framework.Update = function(viewmodel, dt)
	viewmodel.HumanoidRootPart.CFrame = workspace.Camera.CFrame

	local humanoid = game.Players.LocalPlayer.Character:FindFirstChild("Humanoid")
	local t = tick()
	local angle = math.cos(t*7)*0.01

	if humanoid and humanoid.MoveDirection.magnitude > 0 then
		local speed = humanoid.WalkSpeed + humanoid.WalkSpeed * humanoid:GetPropertyChangedSignal("WalkSpeed"):Wait()
		local swing = math.clamp(humanoid.MoveDirection.magnitude / speed, 0, 1) * 0.5
		angle = angle + math.sin(t*20)*swing
	end

	viewmodel.HumanoidRootPart.CFrame = viewmodel.HumanoidRootPart.CFrame * CFrame.Angles(0, angle, 0)
end