How to make a object follow another on only 2 axises?

So basically I want object 2 to be as if its parented to object 1 but only move on the x and z axises of object 1. So I tried using something similar to transform.position.x = objectOne.transform.position.x; and after that transform.position.y = objectOne.transform.position.y;…but nothing that I tried worked…please help…and sorry I’m not able to screen shot my C# code.

Oh sry…I meant objectOne.transform.position.z not y