It's only natural for someone who comes to Node-red with a bit of programming knowledge to leap into the function node. After all, it's the only bit that looks like a program.
However, this is generally not a very good idea.
It's like buying a comprehensive toolbox, throwing away all the tools except the hammer and using it to make your own.
Yes, a trigger node is the solution here. This flow might look something like this:
What does your version look like?
If you have GPIO-in nodes, these will reflect the actual pin status. Have you chosen appropriate pins? Have you configured pull-up/down resistor options?
Definitely don't copy my pin selection, it's random.
There is a discussion about that at https://discourse.nodered.org/t/toggle-gpio-input/60643/7
Do not wire up physical buttons or relays until you are sure. There are countless tutorials on raspberrypi.com and it's associated sites, youtube and elsewhere.
So you asked an infinite number of monkeys to write you a program and it didn't go well. How surprising is that?