How do I call a script to save a score?

Hello all.
If I want to call the below script in the end scene to save the player’s final score at the end of the game, can I put a javascript block inside the end scene?
We need to get the score from the game and register it on the server.
If so, could you please tell me at what point and how to enter the javascript (the end of game scene is divided into success and failure).

[script]
window.parent.postMessage(“1234”, “*”);
“1234” is the final score