I commented these lines of codes and still the same error, this code is just checking if the type of spawn item is weapon, just delete he first index which is not a weapon and place the corresponding ammo bullet to that weapon which was ready to spawn, and spawn both of them.
I will now be trying what you recommended and will inform about the output