The max function is used to pick the highest number in a set of numbers. In this case, there are only 2 options:
2 + stars
levelsat(CurrentLevel)
The result is the value that is highest. If 2 + stars == 2 and levelsat(CurrentLevel) == 0 then the result of the function will be 2.
Now, what do 2 + stars and levelsat(CurrentLevel) represent? After a quick read through, this is what I understand the values to mean:
2 + stars: represents the animation frame to be stored in the array according to the number of stars earned in the level. You add 2 because there are a few frames before the frames with stars so if the player beat the level but didn't earn any stars, the frame to display will be the completed frame with no stars.
levelsat: appears to be the name of the array storing the information for what frame to show but I don't see any other place this name is used. I think this should be replaced with the name of the array and may just be a typo.
CurrentLevel: is a global variable representing which level you are on.
levelsat(CurrentLevel): If my understanding of levelsat is correct, this means get the value of the array at the position matching CurrentLevel.
Given the above, the condition max(2+star,levels.At(Currentlevel)) means:
store the number of stars earned (plus the offset) if it is higher than the previous high score already stored in the array. So if a player previously earned 2 stars and this game only earns 1, the number of stars stored remains 2 but if they earn 3 this time, the number changes to 3.