Function Freeze

My code is randomly freezing for whatever reason, or at least deciding not to run a block of code as the program still relays info to me non-stop. I say randomly as when I close and re-open the program, it mostly fixes itself until the next run. I’ll include the part of the code its refusing to run and the file the function originates from, I have no clue what is happening, and I hope you guys might have ideas!
It will probably mainly be from the main file, as the code runs sometimes event without any modification, but checking the origin file couldn’t hurt I suppose.

Chunk refusing to run

elif event.type == pygame.MOUSEBUTTONDOWN:
                if self.mouse_pos[0] in range(self.CapClick.Cap_rect.left, self.CapClick.Cap_rect.right) and self.mouse_pos[1] in range(self.CapClick.Cap_rect.top, self.CapClick.Cap_rect.bottom):
                    self.CapClick.click()

Function origin

 def click(self):
        self.game.data.data["Caps"] += 1
        self.game.sound.CapClicked = pygame.mixer.Sound("sfx/items/bottlecaps/up/ui_items_bottlecaps_up_0" + str(random.randint(1,4)) + ".wav")
        self.Cap_img = pygame.transform.scale(self.Cap_img, (self.half_Cap_img_width, self.half_Cap_img_height))
        self.CAP_OFFSET = 45,45
        if not self.size_revert():
            self.Cap_img = pygame.transform.scale(self.Cap_img, (self.half_Cap_img_width, self.half_Cap_img_height))
            self.CAP_OFFSET = 45,45
        
    def size_revert(self):
        time_now = pygame.time.get_ticks()
        
        if time_now - self.prev_time > 1000:
            self.prev_time = pygame.time.get_ticks()
            self.Cap_img = pygame.transform.scale(self.Cap_img, (RES[0]/4, RES[1]/4))
            self.CAP_OFFSET = 0,0

you will need to provide the code necessary to run the script and reproduce the issue if you want help debugging, and describe how to reproduce the issue. A small part of the code is not enough