Match 3 game, hint, "invalid get index"

3.5.3 Godot Version

I’m making a match 3 game (like candy crush) and I’m doing a hint, but I have had many errors, Mostly with “Invalid get index ‘0’ (on base: ‘Array’)” and “Invalid get index ‘6’ (on base: ‘Array’)”
I’m using those videos: https://www.youtube.com/watch?v=LwtyLSCbTt4&list=PL4vbr3u7UKWqwQlvwvgNcgDL1p_3hcNn2&index=51
The part of the code that the error marks is:

func find_all_matches():
	var hint_holder = []
	clone_array = copy_array(all_pieces)
	for i in width:
		for j in height:
			if clone_array[i][j] != null:
				if switch_and_check(Vector2(i, j), Vector2(1, 0), clone_array):
					#add the piede i,j to the hint holder
					if hint_color != "":
						if hint_color == clone_array[i][j].color:
							hint_holder.append(clone_array[i][j])
						else:
							hint_holder.append(clone_array[i + 1][j])
				if switch_and_check(Vector2(i, j), Vector2(0, 1), clone_array):
					#add the piede i,j to the hint holder
					if hint_color != "":
						if hint_color == clone_array[i][j].color:
							hint_holder.append(clone_array[i][j])
						else:
							hint_holder.append(clone_array[i][j + 1])
	return hint_holder

func generate_hint():

if hint:
	hint.call_deferred("free")
var hints = find_all_matches()
if hints != null:
	var rand = floor(rand_range(0, hints.size()))
	hint = hint_effect.instance()
	add_child(hint)
	hint.position = hints[rand].position
	hint.set_up(hints[rand].get_node("Sprite").texture)

Please, help.

First, please use the code formatting tool so your code makes sense.
Next, please indicate the line that throws the error.

When you get array index errors, it’s telling you that your array is too short (or empty) and you are trying to read values that are not there.

I see you are cloning ‘all_pieces’ - are you sure this array has anything in it?

Yeah, the plroblem is in the line

hint_holder.append(clone_array[i][j + 1])

the grid is 5x5, so I think the error is when j = 5, so j + 1 = 6 and 6 isn’t on the array, but I don’t know how to solve this