Slerp look at on the y axis?

Hi, I have been looking at some examples for this, but this is not working, I just want the object to look at another object but only rotate around the y axis, but the object looks at the sky isntead. This is the script:

using UnityEngine;
using System.Collections;

public class stuff : MonoBehaviour {

	public Transform target;
	public float velocity;
	
	void Update () {
		transform.rotation = Quaternion.Slerp(transform.rotation, Quaternion.LookRotation(target.transform.position - transform.position), Time.deltaTime * velocity);
	}
}

Thanks in advance.

Remove the ‘y’ component of the direction you pass to LookRotation().

void Update () {
   Vector3 dir = target.transform.position - transform.position;
   dir.y = 0.0f;
   if (dir != Vector3.zero) {
       transform.rotation = Quaternion.Slerp(transform.rotation, Quaternion.LookRotation(dir), Time.deltaTime * velocity);
   }
}