IndexOutOfRangeException: Index was outside the bounds of the Array

I’m still relatively new to unity, I’m trying to create a script to handle weapon information (like ammunition, damage, name etc) and handle weapon switching. My script is giving me the above error but not providing a line so I don’t know where it is occuring

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

public class weaponManager : MonoBehaviour
{
    public GameObject weaponHolder;
    public Transform[] weaponHolderChildren = new Transform[9];
    public List<GameObject> weaponObjects = new List<GameObject>(9);
    public List<weaponClass> weapons = new List<weaponClass>(9);
    public GameObject testObject;
    int currentWeapon;
    
    void Start()
    {
        weaponHolderChildren = GetComponentsInChildren<Transform>();
        for (int i = 0; i < weaponObjects.Count; i++)
        {
            weaponObjects.Add(weaponHolderChildren*.gameObject);*

}
int currentIndex = 0;
foreach (GameObject weaponGameObject in weaponObjects){
weapons[currentIndex].weaponObject = weaponGameObject;
weapons[currentIndex].weaponName = weaponGameObject.GetComponent().weaponName;
weapons[currentIndex].damage = weaponGameObject.GetComponent().damage;
weapons[currentIndex].maxAmmo = weaponGameObject.GetComponent().maxAmmo;
weapons[currentIndex].ammoPickupSize = weaponGameObject.GetComponent().ammoPickupSize;
weapons[currentIndex].ammoPickupName = weaponGameObject.GetComponent().ammoPickupName;
currentIndex++;
}
currentWeapon = 0;
setActiveWeapon(currentWeapon);
}
void Update()
{
}
public void testForWeaponInput()
{
}
public void setActiveWeapon(int passedWeapon)
{
int currentIndex = 0;
foreach (weaponClass weapon in weapons)
{
if (currentIndex == passedWeapon)
{
weapon.weaponObject.SetActive(true);
}
else
{
weapon.weaponObject.SetActive(false);
}
}
}
}

You loop endlessly through the list and add new items to it. You end up trying to get the item at index 9+ from weaponHolderChildren which should only have 9 items (max index = 8).

     for (int i = 0; i < weaponObjects.Count; i++)
     {
         weaponObjects.Add(weaponHolderChildren*.gameObject);*

}
Since you designated the capacity of the list, you probably wanted to reassign existing items rather than add new ones.
for (int i = 0; i < weaponHolderChildren.Length; i++)
{
weaponObjects = (weaponHolderChildren*.gameObject);*
}
And keep in mind that your code is designed only for the same number of elements in all arrays (weaponHolderChildren, weaponObjects, weapons). It’s easy to get another out of range error.
Aslo
GetComponentsInChildren()
include parent too.