I keep getting this critical error.

No. This error means you are trying to access an index of an array, declared somewhere, which surpasses the actual size of the array during the time the index was given for read.
Like, if you have array of size 2, only possible indexes are 0 and 1; not 2 which implies an array of size 3 at least…