No access to global variables?

To answer your question directly, yes, $wpdb is “auto loaded and set up to global by WordPress” but by loading wp-content/themes/roots/script.php directly you are skipping over the WordPress boot process and loading the file exactly as if WordPress did not exist. That is why the normal WordPress objects and constants aren’t available. They haven’t been loaded, because WordPress hasn’t been loaded. You get the same problem, or similar, trying to load any other template or plugin file out of sequence.

The directory the file(s) are in is irrelevant. Files are not “autoloaded” just because they are in a particular directory, with a couple of specific exceptions– with template hierarchy files for example– and that only works because WordPress was written to look for and load particular files from particular places.

As stated in a comment to the question, you need to be using the AJAX API. There are plenty of questions here to help with that not to mention tutorials in other places and the Codex itself.