Fixed $script error when environment is invalid.