transform.position changes on play

hi when ı play my game gameobjects transform.position.z value changes and it is about script that below when ı uncheck the script it does not change

gameobjects connected to camera and two has different transform.position values

float z;
    private float length, startpos;
    public GameObject cam;
    public float paralaxeffect;

    void Start()
    {
     
        length = GetComponent<SpriteRenderer>().bounds.size.x;
        transform.position = cam.transform.position;
         z = transform.position.z;

    }

    // Update is called once per frame
    void Update()
    {
     
      

     
        float dist = (cam.transform.position.x * paralaxeffect);
        float y = (cam.transform.position.y*0.02f);
        float x = startpos + dist;
 
        Vector2 vec = new Vector3(x, y,z);
        transform.position = vec;
    }

ı fixed it first ı was trying vector2 to transform.position so z value is being empty second ı was getting camera location on start so it sets to camera location