Your Serial Input reading routine is not the way it is typically done. Please review Serial Input Basics which is the fundamental tutorial about how to read a message and parse the data from it.
What Arduino are you using?
Using String objects instead of null terminated character arrays can create issues.