> For the complete documentation index, see [llms.txt](https://code-after-sex.gitbook.io/script-documentation/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://code-after-sex.gitbook.io/script-documentation/cas-advanced-loading-screen/closing-the-screen.md).

# Closing the screen

How Advanced Loading Screen closes. Auto shutdown on spawn, external shutdown by a character resource and the Finish export for a clean fade out.

The resource uses `loadscreen_manual_shutdown`, so the screen stays until something closes it. `Config.Shutdown` in `config/config.lua` decides what:

```lua
Config.Shutdown = {
    mode = "external",
    events = { "playerSpawned" },
    fadeMs = 900,
    safetySeconds = 0,
}
```

## Auto

`mode = "auto"`: when one of `events` fires on the client, the screen shows 100 %, fades the music and closes after `fadeMs`. Use it when no other resource closes the loading screen. Add your framework's own "character selected" event to `events` if `playerSpawned` comes too early or too late.

## External

`mode = "external"`: your character creator, multicharacter or spawn resource calls `ShutdownLoadingScreenNui()`. Most of them already do. For a clean 100 % and music fade first, call the export a moment before:

```lua
exports['cas-loadscreen']:Finish()
-- later
ShutdownLoadingScreen()
ShutdownLoadingScreenNui()
```

## Safety net

`safetySeconds > 0` closes the screen anyway that many seconds after the client scripts start, in case nothing else does.

{% hint style="warning" %}
If players stay on the loading screen forever, nothing is calling `ShutdownLoadingScreenNui()`. Switch to `"auto"` or set `safetySeconds`.
{% endhint %}
