How to scroll a scrollbar for a ScrollRect smoothly?

I have a ScrollRect to which I add content to. When it reaches the point where the content is longer than the ScrollRect (ie when the ScrollBar’s value changes from 0), I want the ScrollRect to scroll all the way down (I do this by tweening the ScrollBar’s value until it reaches 0). However, my problem is that I can’t figure out how to do this smoothly over time.

Here’s my code snippet:

		public void Update() {
		if (scrollbar.size < 1 || scrollbar.value > 0) {
			LeanTween.value(scrollbar.value, 0, duration).setOnUpdate((float val) => {

				if (scrollbar.value == 0) {
					LeanTween.cancel(this.gameObject);

				} else {
					scrollbar.value = val / scrollAdjustment;
				}

			});

		}
	}

I tried using “Time.deltaTime” and “Time.time” in place of duration and it did not seem to matter. Here’s a gif of what happens:

204228-unity-2umoznm7pd.gif

(In this example, I used “duration” that had the value of 5 (the idea was to have the transition take 5 seconds) and “scrollAdjustment” was 50 but it did not seem to matter what I set either of these values to.

You can see it instantly snaps to the bottom. I’d like this to be a smooth transition. Any help is appreciated!

In the end, following the tutorial in this video solved my issue: