The function does not work when the button is pressed.

Can you please post some code so we can see what you are doing?