Feedback every 6 trials

Your code looks fine to me. What’s the number of repetitions in the trials loop?

You can try to debug this by inserting print() statements for all relevant variables and checking in the console if at any point something unexpected happens to them. You can also send me a copy of the experiment so I can have a look.