Rotating to match another object

Hello, I’m trying to rotate an object to the same angle as another object using Quaternion.RotateTowards. This works fine when I just flat-out set the rotation of the object to that of the target - no problems there. However, I also need to preserve the Y axis - and every time I try this, it goes weird and the object will only rotate a microscopic amount:

8506181--1133039--upload_2022-10-11_20-36-16.png

The code I’m using is this:

if (rayObjectHit != null)
{
       targetRotation.x = rayObjectHit.transform.rotation.x;
       targetRotation.z = rayObjectHit.transform.rotation.z;
}
transform.rotation = Quaternion.RotateTowards(transform.rotation, Quaternion.Euler(targetRotation), Time.deltaTime * playerRotateSpeed);

I’m assuming that injecting the target rotation like this is a bad idea - but I’m honestly out of ideas.

RotateTowards moves it over a lot of calls, so it won’t do much if you just call it once. Is this in Update?

The RotateTowards is in update. I’ve tried putting the other stuff in multiple places - always with the same effect.