In your case, the “slots” variable is larger than the actual size of the “slot” array. You are basically trying to access a place in the array that does not exist. Also, where are you reducing the size of the “slots” variable? Your loop will go until 1 < slots, which in the case you’ve shown will be never (since slots value never changes) or always (in which case it won’t even enter the loop).
Instead of using the “slots” variable, try using slot.Length
This is what I was going to do, because it is what i did for other c# projects outside of unity, but I had trouble getting it to work, thank you for your help