I'm working on a tennis statistics app and trying to accurately track the percentage of second serves that go in in the tiebreak, but something isn't working properly in the way I record and store that data. I'm trying to keep track of key serve statistics, specifically: First serve in count Second serve in count Aces Double faults Points won on first/second serve And calculate serve-in percentages accordingly I'm using the following stats dictionary to store player data: stats = { "player1": { "serve": { "first_serve_in": 0, "second_serve_in": 0, "aces": 0, "double_faults": 0 }, "points": { "points_won": 0, "points_on_serve": 0, "points_won_on_serve": 0, "points_won_first_serve": 0, "points_won_second_serve": 0 } }, "player2": { "serve": { "first_serve_in": 0, "second_serve_in": 0, "aces": 0, "double_faults": 0 }, "points": { "points_won": 0, "points_on_serve": 0, "points_won_on_serve": 0, "points_won_first_serve": 0, "points_won_second_serve": 0 } } } Navigation flow of the app, in the tiebreak: You start on the FirstServe screen. If the first serve is in, the app records first_serve_in += 1. If the first serve is a fault, the app goes to the SecondServe screen, sets the second_serve status and second_serve_buffer to True (serve_status_tiebreak in FirstServeClass) If the second serve is in > UpdateScore() > check if sercond_serve_status is True then increases second_serve_in += 1. The buffer is reset at the end of each point The tracking of second_serve_in seems inaccurate or not incrementing correctly. Either: It's not saving when I press the button on second serve, The calculation logic for second serve percentage is flawed. I suspect it might come from: The transition between FirstServe and SecondServe Or how the callback function is set when the second serve is hiit Here’s a breakdown of what's going wrong: A first_serve_status = True is triggered, but it does not transition to second_serve_status = True afterward — meaning second serve stats (like second_serve_in or points_won_second_serve) never get updated. The conditions in the function go_to_SecondServe() likely need to be redefined or adjusted, because the logic doesn't seem to switch properly when a first serve is missed. There's also something off in the status_serve_tiebreak() function: when the buffer is True for one player, a first_serve_status = True is being triggered for the other player, which should not be the case. That incorrect switch seems to mess up who is actually serving and which serve it is. I need help with: How to reliably track when the second serve is in (only after a fault on the first serve) Ensure stats[current_server]["serve"]["second_serve_in"] is incremented correctly Continue reading...