When you run this the first time you first call the inbuilt function tf and then later you create a variable, which is named tf also:
TFmotor_OL = tf([0 motor.gain],[motor.timeConstant 1]);
.
.
.
tf = 0;
Since you not clear the workspace, the next time you run the function the call of tf with brackets will be interpreted as the indexed call of the variable tf, not the function that you want to call.
To avoid this you should rename your variable. It is never a good idea to name variables or scripts like inbuilt functions.