Error 507: Unable to connect. Is the device turned on? (Eventhough it is and is connected)

Hello, so I have this project and it had multiple screens and I do know that by going to the next screen it will cut off the Bluetooth connection. So I came up with a solution to disconnect the bluetooth each time it goes to the different screen then reconnect it once again. It worked in the beginning but now it shows the "error 507: unable to connect, is the bluetooth turned on?" eventhough the bluetooth is turned on and is actually connected... I know it is connected because it is blinking slowly, and I added a text to speech to tell me if the bluetooth is connected or not which it says it is. Any idea why this is happening?