In my opinion, the logic of the code I gave you is fine. If your program isn't working, I suggest trying these things:
1.) Create a new program that implements only the features you think aren't working properly so you can focus only on what you need to. This helps boil the problem down to a specific bug or set of bugs.
2.) Ensure all hardware connections are properly made. You might even want to run a test to see if the joystick is running properly with a simple analogRead() to the serial plotter just to make sure (and test the output limits of the stick).
3.) Use Serial prints to the serial monitor (or plotter) to see if certain sections of code have been executed (and when) or to see how the variable values change.
4.) Post a photograph of your hardware/connections.
Do some testing and come back with any specific problems you run up against. Until then, we can't help much.