The StackScript itself needs to exit for the SS environment to clean up, else the SS will re-execute – so if you want to reboot you need to somehow 'schedule' it (temporary cron job, fork a process with a delay-before-rebooting, etc). Setting up what to happen after that step will be up to you.
-Chris