Determining Loading time/Loading screen

Now, I just want to understand loading screens a bit more. How do you determine the wait time(Progress bars)/when to stop showing the loading screen? For example, I have a game, that a loading screen would fit perfectly in. The game has about a 5 second extreme lag moment while the terrain/cave systems are generating, a perfect time for a loading screen “Generating Terrain”. Now I know that the waiting time would be different for other computers. Is it ALL in the scripts? (like once the generating is complete, turn off loading screen(Although, this wouldn’t work for me, the chunk generation is independent scripts)) Or is there some other way to determine waiting time/when to stop a loading screen? Also, although I have made this question look specific towards a script/game, I was just using that game as an example just to understand loading more.

Thanks in advance.

Personally I haven’t done one yet, but will very likely run into the same issue at some point. So thinking about it - perhaps the script performing the setup/loading/whatever could generate an event after finishing particular steps or even just after it’s finished the work. Assuming you don’t need to have a specific amount of time displayed on the “loading” screen, the associated script could listen for the events coming from the setup script and update accordingly. When the final event is received it could end the “loading” screen. I’ll probably use this method unless someone has better suggestion.