Why when setting emptygameobject child position to 0,0,0 it's not in the right position like parent?

I have empty gaemobject in the hierarchy.

Then in the script i create another empty gameobject and parent it as child to the empty gameobject in the hierarchy. The empty gameobject in the hierarchy is at position 374,0,0 and i set the child gameobject to 0,0,0

The script is attached to the empty gameobject in the hierarchy.

At the top of the script:

private GameObject emptygameobject;

In the Start:

private void Start()
    {
        emptygameobject = new GameObject();
        
        int keys = 0;
        foreach (var thisKv in List)
        {
            if (emptygameobject.name != result[keys])
            {
                emptygameobject.name = result[keys];
                emptygameobject.transform.parent = transform;
                emptygameobject.transform.localPosition = new Vector3(0, 0, 0);
                Instantiate(emptygameobject, emptygameobject.transform.localPosition, Quaternion.identity);
            }
            keys++;

            var key = thisKv.Key;
            foreach (var thisValue in thisKv.Value)
            {
                GameObject cube = GameObject.CreatePrimitive(PrimitiveType.Cube);
                cube.transform.parent = emptygameobject.transform;
                cube.transform.position = new Vector3(-thisValue.Y, 0, thisValue.X);
            }
        }
     }

This is where i set the emptygameobject position to 0,0,0

emptygameobject.transform.localPosition = new Vector3(0, 0, 0);

This is a screenshot of the empty gameobject in the hierarchy I did in the menu: GameObject > Create Empty

The position of the gameobject is X = 374 Y = 0 Z = 0
The Hello World is on the right of the terrain. But i moved before running the game the gameobject to position 374 on the x.

Then i set the child empty gameobject in the script to 0,0,0

But still the Hello World is on the right of the terrain and not on the terrain.
The Hello World should be start from the terrain position 0,0,0 to 374,0,0

Your line has no effect because you set the local position on an emptyObject newly created and so it is already at 0,0,0.
You must change the local position to the cube, after added it to the parent.

I don’t know if it’s what you’re looking for but change this line from :

//from
emptygameobject.transform.localPosition = new Vector3(0, 0, 0);
//to
emptygameobject.transform.position =  new Vector3(-thisValue.Y, 0, thisValue.X);

and this

//from:
cube.transform.position = new Vector3(-thisValue.Y, 0, thisValue.X);
//to
cube.transform.localPosition =  Vector3.zero;

I found the solution.
I needed to set the emptygameobject localPosition to 0,0,0 after the loop:

int keys = 0;
        foreach (var thisKv in pointsList)
        {
            if (emptygameobject.name != result[keys])
            {
                emptygameobject.name = result[keys];
                emptygameobject.transform.parent = transform;
                Instantiate(emptygameobject);
            }
            keys++;

            var key = thisKv.Key;
            foreach (var thisValue in thisKv.Value)
            {
                GameObject cube = GameObject.CreatePrimitive(PrimitiveType.Cube);
                cube.transform.parent = emptygameobject.transform;
                cube.transform.position = new Vector3(-thisValue.Y, 0, thisValue.X);
            }
        }

        emptygameobject.transform.localPosition = new Vector3(0, 0, 0);

Now it’s working perfect.