Since I do not know what "buggy" means or what happens when you run the script, I will suggest troubleshooting strategies.
1. Eliminate the second large
If block, so that you can troubleshoot only the first block until it works properly.
2. Display values of key variables, such as play20, so that you know what these values are, when they are defined or assessed.
3. Add other visual cues (tooltip, MsgBox, etc.), so that you know which sections (e.g., Stop40) are executing, and when.
4. Use some of the AHK tools such as
KeyHistory or
ListLines, so that you know what is being clicked, sent, etc.
5. Fix your indentation so that it uses a sensible and consistent approach. It currently generates confusion, and you might be missing some block definitions where you believe that you currently have them. For example, some of your
If blocks are indented, while others are not. Some of your braces are indented, while others are outdented. From my perspective, this is not only hard to follow, but might be increasing the chance that you introduce a bug into your coding.