Unity Instantiate problems

i got this script

using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class Spawner : MonoBehaviour
{
    public Vector3 scaleChange;
    public float X;
    public float position;
    public GameObject Spawnpos;
    public Transform spawnposT;
    public float timefromlastspawn = 0f;
    public GameObject Prefab;
    // Start is called before the first frame update
    void Start()
    {
        scaleChange = new Vector3(1f, 1f, 1f);
    }

    // Update is called once per frame
    void Update()
    {
        X = spawnposT.transform.position.x;
        Prefab.transform.localScale = scaleChange;
        position = Random.Range(-10, 10 * Time.deltaTime);
        timefromlastspawn += Time.deltaTime;
        if (timefromlastspawn > 5f)
        {

            SpawnBird();
            timefromlastspawn = 0f;
        }
    }
  public void SpawnBird()
    {

        Prefab.transform.parent = Spawnpos.transform;
        Instantiate(Prefab, new Vector3(X, position, 0), Quaternion.identity);
    }
}

and it spawns objects but for some reason the y position is always 6.7 and something.
anyone know the reason?

Have you checked if the prefab you’re spawning has its transforms zeroed out? If for example, your prefab has a Y of 6.7, then when it will be instantiated with that same value.

This defines the y position. But it will probably never take the value of 6.7 unless there is heavy frame drop. Something else should be changing the position of the new object after the instantiation.