Hi
If you want to write the text during the game, then you should draw the text object every frame, into your main loop, and you can also add a condition if you want
while (true) {
.....
text.setString(score.toString());
window.draw(text);
........
}