Aim Down Sight script ArguementOutOfRange error

Hey guys I have an ADS script but I get an error when I try to aim

this is the error
ArgumentOutOfRangeException: Argument is out of range.
Parameter name: index
System.Collections.Generic.List`1[WeaponScope].get_Item (Int32 index) (at /Applications/buildAgent/work/3df08680c6f85295/mcs/class/corlib/System.Collections.Generic/List.cs:633)
PlayerController.ADSController () (at Assets/scripts/PlayerController.cs:156)
PlayerController.FixedUpdate () (at Assets/scripts/PlayerController.cs:59)

here is my code

    public bool IsAiming;
    void Start()
    		CurrentWeapon = WeaponList[0];
    	public void FixedUpdate()
    public void ADSController()
    		if (Input.GetButton("Fire2"))
// The error was refering to this
    			IsAiming = true;
    			ADSHolder.localPosition = Vector3.Lerp(ADSHolder.localPosition, CurrentWeapon.Scopes[CurrentWeapon.CurrentScope].adsposition, 0.25f);
    			IsAiming = false;
    			ADSHolder.localPosition = Vector3.Lerp(ADSHolder.localPosition,, 0.25f);
    public class WeaponInfo
    	public int CurrentScope;
    	public List<WeaponScope> Scopes = new List<WeaponScope>();
    public class WeaponScope
    	public string name;
    	public float fov;
    	public Vector3 adsposition;
    	public Transform scopetransform;

According to the error you got, the exception was thrown from this function:

WeaponScope System.Collections.Generic.List'1[WeaponScope].get_Item(Int32 index)

Even though you are not calling that function directly in your code, odds are that it’s getting called indirectly when using the subscript operator(the square brackets in the List object, since that gets the WeaponScope item at the integer index, or in other words, WeaponScope get_Item(Int32 index)). See?

Now, why would you get an ArgumentOutOfRange exception from the get_Item function? Well, as this explains, an ArgumentOutOfRange exception happens when you’ve passed a number into a function and the number wasn’t in the valid range.

Take for instance this scenario: you write a function that only works if you put in any number from 0 through 10. But, you know that things will not work right if you use any other number outside of that range. If you want to make sure users of your function don’t misuse it, one way is to make it throw an ArgumentOutOfRange exception when the number given to the function is not 0 through 10, like so:

// if under 0 or above 10, throw error.
if(num < 0 || num > 10)
    throw new ArgumentOutOfRange("You didn't enter a number between 0 and 10!");

If I write this code in a function, it makes sure that users of my function don’t use the function in ways it wasn’t intended to be used.

So, for you to be getting an ArgumentOutOfRange exception from get_item() you must be giving an index value to get_Item() that isn’t valid. From my years of experience, I can guarantee you the issue is that you are passing in an index that just doesn’t exist. You should check the value of CurrentWeapon.CurrentScope and see if it is less than 0 or greater than CurrentWeapon.Scopes.Count.

I hope that helps!