What is the Arduino board?
How is the ESP connected to the mystery Arduino board?
You seem to be reading from the ESP serial port before you know if anything is available in the serial input buffer. The serial input basics tutorial has robust methods for reading and parsing serial input.
Read the forum guidelines to see how to properly post code and some hints on how to get the most from this forum.
Use the IDE autoformat tool (ctrl-t or Tools, Auto format) before posting code in code tags.
Please go back and fix your original post by highlighting the code and clicking the </> in the menu bar.