The simplest would be a condition to see if the variable is less than 5.
Global number var=0
On click
Var < 5
— add 1 to var
If you want something more deluxe like being able to increase the var by other means then you’ll have to use another var as well.
Global number var=0
Global number clickcount=0
Global number keypresscount=0
On click
Clickcount < 5
— add 1 to var
— add 1 to clickcount
On key press
Keypresscount < 5
— add 1 to var
— add 1 to keypresscount