You are going to need a lot more logic than what you have. You could store the scores in a global variable per level. You also need a global variable to track the score in the current level to compare later, let's call this score.
So when you finish the level let's say 'score' =2(stars) you compare it to level 1 variable, if score greater than 'level 1' variable then set 'level 1' to score else do nothing. So if level 1 was already 3 (stars) then it would not change from 3, but if you didn't play level 1 yet so it is 0 or a lower score like 1, it would update to 2.