Hey Creators,
In 2022, we announced RunContext, a property of scripts that lets you control where they run. Today, we’re excited to introduce the Plugin RunContext, a new option that can be used for scripts in Studio plugins. With this change you’ll now be able to dynamically enable and disable scripts, use Parallel Luau, and access autocomplete for plugins.
Overview
Unlike regular scripts, scripts in plugins would only run once if they’re enabled when a plugin loads. With the new RunContext option they now behave the same as regular scripts, automatically running when they are enabled or if they are cloned into the plugin.
This means you’ll now be able to use Actors in plugins. For example:
Cloning Actors in a plugin
With the Plugin RunContext, if you set ActorScript
’s RunContext to Plugin, it will be Enabled and cloned, and run twice (once in each Actor). This pattern can be used to spawn any number of Actors to do a large amount of parallelizable work (see Parallel Luau for more information).
Autocomplete for the plugin global
Alongside this update, we’re enabling autocomplete for the plugin
global by setting its type to Plugin
. Plugin methods will autocomplete in scripts inside of the PluginDebugService, and in scripts with a Plugin RunContext, giving you valuable type information even if you’re developing your plugin outside of the PluginDebugService.
Feedback
If you have any feedback, questions, comments, or concerns about this feature, please post them here!
FAQs
Click here to view the FAQ!
What if I have a Script with the Plugin RunContext in my Workspace/ServerStorage/StarterPlayerScripts/etc?
- A Script with the Plugin RunContext will only run if it is the descendant of a plugin, and nowhere else. You can use the Plugin RunContext to develop and organize your plugin anywhere in Studio without fearing that its scripts will run when you press Play.
What happens if I change the RunContext of a plugin script in the PluginDebugService?
- If you change the RunContext from Legacy to Plugin, the script will be restarted and run immediately. If you change the RunContext from Plugin to Legacy, the script will terminate as usual, but it will not restart until the plugin itself is reloaded.
Are there any plans to extend full support for new scripting features to the Legacy RunContext in plugins?
- No, as this change might create issues for existing plugins that are not designed with the new functionality in mind.
What happens if my plugin script calls plugin:CreateToolbar(...)
or plugin:CreateDockWidgetPluginGui(...)
, and then gets restarted?
- An error will be thrown if those function calls use the same ID each time.