$Script:Variable work in debug mode but not in build

Tool: Powershell Tools Visual Studio 2022
Version: 

Hi Community,

I declared a variable :
[Boolean]$sortDescending = $False
When I modify it in a function, it works in debug mode. It no longer works in the compiled exe.

 $LV_WSFilesHeaderName.add_Click({
        if ($sortDescending) {
            $FolderWS.ListFiles = $FolderWS.ListFiles | Sort-Object -Property FullName -Descending
            $Script:sortDescending = $False
        }
        else {
            $FolderWS.ListFiles = $FolderWS.ListFiles | Sort-Object -Property FullName
            $Script:sortDescending = $True
        }
        $XMLForm.DataContext[1] = $FolderWS
    })

Thank you for your attention