Pretty simple SoftwareSerial problem

#include <SoftwareSerial.h>
SoftwareSerial mySerial(2, 3); // RX, TX

void setup() {
  // put your setup code here, to run once:
  mySerial.begin(9600);
  Serial.begin(9600);
  Serial.println("debug1");

  mySerial.write("AT");
  Serial.println("debug2");
  while (mySerial.available() > 0) {
    Serial.println("debug3");
    Serial.write(mySerial.read());
  }
}

void loop() {
  
}

I have this code here, slightly edited from something found in a github repository, It sends an command to a AT-09 BLE module, and is supposed to wait for a response. As you can see, there are 3 debug notes, of which 2 appear. Debug 3 which is found in the while loop does not appear in serial monitor. According to official Arduino documentation, the .available checks how many bytes are available to read, and here I check if it is above 0, which it should be if the BLE module responds with OK, so what is the issue? is there a problem with the module where it is not responding to the command?

Edit: Some unmentioned details: I am using an Arduino nano (old bootloader), and when i remove the while loop, there is something that responds, but it is not the "OK" expected. Instead it provides a � character

Post where you found that code, it appears to be crap.

Serial comms, especially at 9600, are glacially slow compared to the processor's speed. No wonder there's nothing in mySerial's buffer when you check it. There's other problems with the code too.

That code does not wait for a response.

Move the while loop into loop().

While the code isn’t any good, it might work if you change the while-loop into a do-while

I suspect the >0 test is being made and fails BEFORE the module can reply.

The code was found here. Thanks for the help!

This did work for this problem. The Module replies as expected now. Thanks