Serial.available acting funny

  float distance = analogRead(1);

The analogRead() function returns an int. Why are you storing that in a float?

  //map float to an int
  int x = (int) distance;

There's no "mapping" going on here.

            data[counter] = String(serialDataIn);

The serialDataIn variable is already a String. There is no reason to make another String instance, and then invoke the copy constructor on that instance, and then delete that instance. That is just uselessly gambling with an already dodgy class.