I'm assuming that you aren't attempting to sort the records as listed in a portal here. That can't be done with a Sort, script step.
I sounds like the second button's script is failing to sort the records for some reason. I'd check the sort step in that script and make sure that it refers to the correct field(s) from the correct table occurrence(s).
Go To Layout is a key step in FileMaker scripts. It establishes a "table Occurrence context" for your script. Each layout refers to a table occurrence box on your relationship graph in Layout setup... (Show Records From). For a given window, each Table Occurrence on your graph maintains a sort order, a found set and a current record. Thus changing layouts may change your context to refer to a completely different set of records.
Go To Layout will also trip several of the Layout based script triggers such as OnRecordLoad and OnLayoutEnter--which can cause an entirely new script to kick in in the middle of the first script's execution--so that's something you have to look out for if you've defined any such triggers for that layout.
If you do a web search you'll find a number of online resources for scripts, calculations and custom functions.
If you go to a book selling site such as Amazon, you can find several books on FileMaker listed. I can't recommend a specific title as the best fit depends on your current training and experience and I haven't read them all myself, but you can read reader reviews on each such title to select the title most appropriate for you.
There are also training videos available--including some that are on YouTube.