I can’t get that code to go into MakeCode. A share link would be better. I can see what you are trying to do with that while loop and yes that is the problem. You want to return to a blank screen after pushing a button (or two).
Presumably you have this running on two micro:bits with each one able to affect the other. A while loop is never a good idea like that. Use the event handlers instead.
There are some timing issues involved in using that loop. You can send so many 0 messages that the receiver gets behind and there is a delay as it tries to get through all the 0 before it can see a 1, 2, or 3. It is best to not send that many messages. You may want to explicitly send a clear screen message when the micro:bit is shaken or something.
If that doesn’t work for you consider a forever loop that knows when to clear the screen based on the last time a message was sent. Since this is for school I leave that up to you.