I want to know how to make scripts, which help to copy one database to another including users,roles,tables,...,data?

I need to do it using only scripts (not .dmp)

I found some third party tool which make such scripts but order of creating objects is incorrect.