that comes with experience, but some sort of rules can get you pretty much out of most troubles.
-When does the issue happen/under which circumstances? (can help identifying the event or behavior).
-what is the problem, and what is meant to happen normally? (very important, if you just don't know what you are doing and go sorta like "well, that feels kind of good, we will keep it", change how you work)
-what could cause the problem? (kind of hard to inspect, but rememeber that in case you cannot identify it, there is an entire community here that may be able to awnser your question, to be fair, if you present your issue in a way similar to a bug report (aka. simplified capx to show the issue, explaining what you want to have, with some screenshots to be precise), I do not see how anyone would have a hard time awnsering you.)
-clean is love, clean is life: do not get messy with your events, you have to be able to read everything you have done without too much trouble (for very complex or repetitive parts, isolations into functions can help).
I recommand having a really clear idea of what you want to achieve before implementing it, sometimes I have discussions that go like that:
"what is the problem?
My object does not shoot like it should.
how should it shoot?
Idk. how you would make it shoot?
That is not my game, I can make suggestions, but I cannot help you doing what you want if you do not know already"
mostly planning ahead, good use of the tools (which are described in the fabulous manual), organisation.
that was the part to help, now the real part.
It happens to me, and not to me, you have this "why it does not work, did I made something wrong??" feeling sometimes, when that happens and you cannot identify the problem, stop, take a breath, do soemthing else, come back, and analyse later, if you still cannot figure it, try to get some help, but I understand this frustration that can come from a lack of organisation or working too much. Find a good rythm, it might be better to work just 5 hours efficiently than forcing you to work 8 hours with the brain that goes on strike, sometimes even then that does not work, rethinking the design can be of help (not do something else completely, but do the thing you wanted without thinking the same way), those are frustrations that even a programmer can fell, because doing a game is an hard work => it is translating the concepts, ideas, mechanics, into a way the computer can understand, that part cannot be understated, and is coming with every tool out there.