How to keep score value after reloading the html page

I have been making a tictactoe game and I want to keep score of each of my winners, the thing is that once one of my players wins, a number is added to the score but once it refreshes to start the next match, the score goes back to 0
I think using localstorage is the key, but im not very familiar with it.
What would be the right approach to it?

//this is the variable that displays the score value 
let playx = document.getElementById('val');

function winnings(){

 alert('Player X WON!');
               
//here the value increments on each wining
               playx.innerHTML++; 

//I imagined this is how the value is stored
               localStorage.setItem('score', JSON.stringify(playx.innerHTML));

//this code below is to reload/restart the match
               maindiv[0].appendChild(parog);              
               setTimeout(reload, 2000);
...

}

// I tried to keep it after refreshing like this but that did not work
 function getScore(){ 
    return   localStorage.getItem('score');
   }
   getScore()