# EndScreen Not Loading My Best Score And Current Score How To Fix?

I am trying to make my endscreen save last score and current score but it just appears as 0 for both everytime I die event he I picked up the coins image so basically it isnt saving my coins I had and my coins I have right now

here is my endScreen

#---------------------------------------------------
def endScreen():
global pause, score, speed, obstacles
# We need to reset our variables
pause = 0
speed = 30
obstacles = []

# another game loop
run = True
while run:
pygame.time.delay(100)
for event in pygame.event.get():
if event.type == pygame.QUIT:
run = False
pygame.quit()

# This will draw text displaying the score to the screen.
window.blit(bg, (0,0))
score = 0
largeFont = pygame.font.Font('BLOODY.ttf', 80) # creates a font object
lastScore  = largeFont.render('Best Score: ' + str(updateFile()),1,(255,255,255)) # We will create the function updateFile later
currentScore = largeFont.render('Score: '+ str(score),1,(255,255,255))
window.blit(lastScore , (800/2 - lastScore .get_width()/2,150))
window.blit(currentScore, (800/2 - currentScore.get_width()/2, 240))
pygame.display.update()

def updateFile():
f = open('scores.txt','r') # opens the file in read mode
file = f.readlines() # reads all the lines in as a list
last = int(file[0]) # gets the first line of the file

if last < int(score): # sees if the current score is greater than the previous best
f.close() # closes/saves the file
file = open('scores.txt', 'w') # reopens it in write mode
file.write(str(score)) # writes the best score
file.close() # closes/saves the file

return score

return last
#----------------------------------------------------------


this is my coins text where I run it on my main loop

    font = pygame.font.Font('times.ttf',29)
score = 0
text = font.render("Hearts  =   " + str(score), True, (255,255,255))
textRect = text.get_rect()
textRect.center = ((80,70))



and here where is when I die the endScreen loads

           if playerman.health < -5:
endScreen()

$$$$

• This looks very similar to your previous question - you might want to wait for an answer to that one first, or edit it to include more information rather than posting a new question. – DMGregory Jun 11 '20 at 1:12

At this point where your score probably should be displayed to the screen you're setting it to 0 before.

        # This will draw text displaying the score to the screen.
window.blit(bg, (0,0))
score = 0
largeFont = pygame.font.Font('BLOODY.ttf', 80) # creates a font object
lastScore  = largeFont.render('Best Score: ' + str(updateFile()),1,(255,255,255)) # We will create the function updateFile later
currentScore = largeFont.render('Score: '+ str(score),1,(255,255,255))
window.blit(lastScore , (800/2 - lastScore .get_width()/2,150))
window.blit(currentScore, (800/2 - currentScore.get_width()/2, 240))
pygame.display.update()


When you assign the score to 0` when you leave the loop (when you leave the end screen) your problem should be solved.