While loop to check database

I don’t like your idea with the loop.

But if you want to solve it in this way you have to wait for when the DB query will be done and then you can do another query

For example with async/await

async function createUsername(USER) {
 var check = false;
 while (check === false) {
            await wixData.query("Teachers")