How to have an object follow another object only on the y axis.

So heres the deal, I have seen multiple posts like this, but none of them are really what I need. I want an object to follow another object only on the y, I don’t want it to teleport to that objects y axis, I want it to follow it with a speed and so that it is not always on the same y axis, but will attempt to follow the player on it.

Given a target transform and writing in Javascript/Unityscript, put this in Update():

      transform.position.y = Mathf.Lerp(transform.position.y, target.position.y, speed * Time.deltaTime);

‘speed’ is a variable you define and initialized. Start with a value of 3.0.