Why is my for loop creating 3 times as many elements as specified?

I have a script that generates a set number of vectors and stores them in an array. When I compile using “expose on spawn”, the array shows that there are 3 times as many elements in the array as the length of the for loop. I am trying to generate a series of points that will be the locations of stars in a galaxy and use the array generated to add and remove stars from the scene based on distance from the player to improve performance while having a vast galaxy to explore. The problems I am having include:

  1. The array being 3 times as long as it should
  2. The stars will add themselves when I get close enough, but they do not remove when further (I think its because the array is way off)
  3. I can visually see stars overlapping, so it is also creating 3 of each star
  4. When I change the number of stars to anything, there are always 3 times as many

I have attached the 5 screenshots related to this issue. Thank you for your help and let me know if you have any questions.

I actually solved the issue of there being multiples of elements in the array. It was adding to the array that was generated during previous compiles. It was getting up to 7 times as many elements sometimes. I added empty array duplicates and set to them in the beginning of the construction script, which clears them every compile. I also noticed I was missing the component to array item connection in the “buildstar” function.

See attached