Mine are trained by keeping them in a pen in the coop or area where you want them to roost, for a t least three weeks. More if they are older or unfamilar with the place (I raise my own keets). After three weeks, I open the door and let them out for a little bit- get on grass, herd them around to see the area, etc. Pen up again. THis gets longer and longer until I let them out for half a day and herd in before dark. Eventually, I will give them access to the pen and let them do their own thing for a while. Ensure they go back in the pen...
Then, all crap hits the fan- I keep them out of the pen! (my free range birds roost in the barn, above the pen). I have to go on evening duty, ensuring they have gotten in the secure barn and eventually they will roost with the others in the upper part of the barn. HAving treats in the barn and always, always, only feed and water in the area you want them to stay. Takes a while but they will learn .
Good luck!