Law and legal regulations provide the framework through which governments prescribe what is acceptable behaviour and what is not. Law acts as a threat. If we don't follow the law there is a risk that we will be found out and punished.
For example, law regulates smoking to the degree that cigarettes are not supposed to be sold to children. If retailers sell cigarettes to children they can be prosecuted.