To be able to connect to your pi from anywhere outside the local network, you will need to make sure that your router is set to port-forward.
To do so you will need to login to your router. If you're using Windows, open the command prompt and enter "ipconfig". Scroll up and find the ip address for the "Default Gateway", and enter this into your browser. If you're using Linux, the command is "ip addr".
It should then load a login page for your router, where you will need to enter the admin username and password. I cannot give you specific instructions after this part as each router has a different interface.
You will then need to search through the settings for an option that says "Port-Forwarding", which is usually a checkbox.
Restart your router and you should be able to connect from outside your local network.