trying to make a lives system for my pygame platformer I am trying to make a lose function that I can just call on the idea is it looks to see how many lives the player has and if it equals 0 it quits that game however I continue to get a UnboundLocalError: local variable 'lives' referenced before assignment only way i have gotten rid of it is by putting lives=5 inside of the if statement but that just resets the lives counter I know it has to do with the placement of where my lives=5 line is but I cannot figure it out
def lose():
if lives>0:
player.x=-6880
player.y=581
lives=lives-1
if lives==0:
print("you lose :'(")
exit()
if player.y>800:
lives=5
lose()
this isn't all of my code just the parts I thought would be necessary to figure out the issue any input is appreciated