RunTimeError: Index was outside the bounds of the array -> RayPerception

Hi,
I am training an AI to teach a car to drive, and I want the side sensors to detect the lane it is not in as a wall so that it does not change lanes. However, this causes the car to switch from the right lane to the left lane at intersections, requiring the sensor to change the tag it needs to detect. I wanted to know if this is possible because when the car reaches that part of the code, the error appear, the phtos shows how is the code and the specific error, I guess is that the problem but not sure at all

        if(rightSide != right)
        {
            if(right)
            {
                normalSensor.DetectableTags.Remove("LaneRight");
                normalSensor.DetectableTags.Add("LaneLeft");
            }
            else
            {
                normalSensor.DetectableTags.Remove("LaneLeft");
                normalSensor.DetectableTags.Add("LaneRight");
            }
        }

.

9899421--1429749--image.png