We are excited to announce RunContext, a new feature for you to try out as part of a Studio beta.
RunContext is a property of Script that allows you to control where it will run in your experience. Initially it has the following options but we may expand on them in the future:
- Legacy - Scripts will run when parented to specific containers. This is identical to the current behavior many of you are used to and is the default for this property.
- Server - Scripts will run anywhere in the place including services such as ServerStorage and ReplicatedStorage but only on the server.
- Client - Scripts will run anywhere in the place including services such as ReplicatedStorage but only on the client.
Each option also has a unique icon to make it easy to tell them apart when you’re editing your experience in Studio.
You can try it out by opening up Studio and changing the RunContext property of any Script in your experience.
Here are a few of the motivations behind us making this change:
- Client and server code can exist in the same place making it easier for them to share resources and for asset creators to make models that ‘just-work’.
- The behavior of Script and LocalScript can be consolidated into a single instance making it easier for us to introduce new script types in the future.
As mentioned before, client and server code can be put in the same place making it easy to create packages that have both! Here’s an example using our Selfie Mode developer module.
To start with we are enabling this feature in Studio to give you time to try it out and for us to ensure there are no outstanding issues. Please try it out and share your experience here! Once we make sure we address the feedback we will enable it in live experiences across the platform.
Will this let players see the source of my scripts?
No. We never replicate the source of your scripts to the client. Instead, if the client needs to run the script we will replicate its bytecode. This only happens if:
- The script is a LocalScript
- The script is a Script with its RunContext set to Client
- The script is a ModuleScript
As an added security measure RunContext can only be changed by plugins in Studio. Even if there was a backdoor in your experience an exploiter would not be able to take advantage of this to change the RunContext and get the bytecode of your server scripts.
What will happen to the 'Legacy' context after release?
Legacy is just the name we are giving to the existing behavior. It will continue to be supported after we fully release this feature so you can continue using it if you prefer to.
How does this affect LocalScripts?
We are planning to update the icon of LocalScript so that it is different from the icon we use for the Client RunContext. Other than that we understand how important they are to so many experiences so we have no additional changes planned for them.
How does RunContext interact with 'Starter' containers?
Starter containers work by cloning their contents locally therefore they will make a copy of any scripts contained in them. If you are using one of the new RunContexts such as Client or Server then both the original scripts and their copies will run. Therefore, you should continue to use the Legacy RunContext or LocalScripts in these containers.
What if I don't want scripts to run in certain places?
Scripts can still be disabled through the use of the existing Disabled property.
What happens if RunContext changes at runtime?
RunContext can only be changed in Studio, either from the properties widget or with a plugin. If its value changes while the script is running then the existing thread will be terminated and the script will start running in the new context.
How does RunContext work with Streaming?
As scripts are streamed in and out from the client they will naturally start and stop executing.
Are there plans for a 'Plugin' RunContext?
Some of you might have noticed that the RunContext enum also contains ‘Plugin’. In the future we are planning to add an option for scripts that should run in plugins specifically.
- The Studio icon does not update in the explorer or script editor. This is temporary and will be resolved before release.
- You may experience different behavior in Studio as we handle replication differently. We are looking at ways to make this more consistent with how RunContext works in experience.
- RunContext will not be saved if you use it in team create. This is temporary and will be resolved before release.
- AutoComplete shows server suggestions for the Client RunContext. This will be resolved in an upcoming release.
- Scripts in ReplicatedFirst do not run before game load. This is temporary and will be resolved before release.