Need Help With Script Error And How To Fix?

NOTE: 2D game here with C#. So I have this error: IndexOutOfRangeException: Array index is out of range. JudaiCoinScript.Spawn () (at Assets/Scripts/Messenger/JudaiCoinScript.cs:52) JudaiCoinScript.Start () (at Assets/Scripts/Messenger/JudaiCoinScript.cs:18) and I’m trying to figure out what’s causing it. I did some research trying to find a solution to my error and I found out some things, but they were not quite helpful in my situation. Here’s my script(WARNING long script, if you are afraid of long scripts please do not click the link): http://pastebin.com/bAVVnsKX

Okay so now the errors appear in two places on the script. The first is where the void Spawn(){ is at, right under it is where the error is at, where it says “Instantiate (obj [Random.Range (0, obj.GetLength (0))], transform.position, Quaternion.identity);”.

The second error is located right under the void Start(){ where it says “Spawn();”. Now as you can tell(if you clicked the link) the code is very inefficient and needs to be cut down. It’s so large because I combined another spawn script with it because it wasn’t working by itself. Anyways please help if you can or if you want to(I mean who would want to help a random guy). Most of you people though are very generous, so thanks you. :slight_smile:

And multiple tags are still not working for me. I guess I’m limited to only 1.

I think it should be Random.Range(0, obj.length) instead of Random.Range(0, obj.GetLength(0))

There seems to be no error present in the script but off the top of my head, are you assigning game objects to your ‘obj’ array from the inspector?

Because if not then you will get an error if you try to access any of the index value of that array since there is no element present in the array (even if you try to access the index zero).