[Live] Script RunContext

Hey Developers,

We are excited to announce RunContext.

What is RunContext?

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.

Why are we making this change?

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.

How can you use it?

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.

Documentation

FAQ

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.

Known Issues

  • 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.
450 Likes
LocalScript requires info from ServerScriptService, is there a workaround?
Is Localscript the same as Script with the Runcontext to client?
Remote Events not firing when script runcontext is set to legacy
RunContext Attribute
FOV Tween won't play?
Orbiting particle effects don't keep up with moving character
NoFreefall Module | Create a similar effect to going beyond the boundaries from Mario Galaxy
Is the RunContext property ready to be used, or is it still only in studio?
Best practice for client only scripts in modules?
New Script RunContext, Whats the difference between a Script running on Client and a LocalScript?
Creating Local Doors
RunContext Client behaviour is wrong
Client sided night not working
Humanoid.Died doesn't trigger in certain situations
Maybe you might not need to use a Network module
Run LocalScripts in the workspace (UniversalLocalScripts) (Obsolete)
Client Replication on NPCS
Run LocalScripts in the workspace (UniversalLocalScripts) (Obsolete)
Questions on RunContext and OOP
Localscript does not reach remoteevent
Help getting animations playing for npc who is being moved using local script
Script running in StarterPlayerScripts?
Script running in StarterPlayerScripts?
Remote not firing from modulescript
Timer Not Working
Scripts within StarterCharacterScripts nested within Folders run when they shouldn't
LocalScripts in StarterCharacterScripts are being run twice (not Scripts with RunContext set to Client)
Do LocalScripts work in the Workspace?
How to create local parts?
Sentinel Universal Anti-Cheat Release
What is the difference between LocalScripts and Scripts with RunContext set to Client?
Script not printing any changed text in textbox
How to make distance for highlight
Injecting LocalScript into clients from server
How to tell the RunContext of a Script at runtime?
Strange Behavior with RunContext
Event fires once, function fires twice
Scripting questions
Why is localscript not running when I enable it in serverscript?

This topic was automatically opened after 11 minutes.

This is a fantastic update for me and the fellow scripters on Roblox! I was wondering why this was not added sooner, but Iā€™m so glad itā€™s added today! Thisā€™ll be very useful for making client-sided scripts to be ran in the workspace for every client and other things of course, but mainly that! Keep up with these awesome updates! Canā€™t wait to see what other improvements will be added! :sunglasses:

45 Likes

I really love this update. This is going to make systems so much more compact and easier to use across multiple projects. I made this comment before using it in a project and realizing its significance:

Iā€™m not sure of the use cases for this? Is this more just to remove the confusion between different kinds of scripts? Canā€™t wait to give it a try.

There are so many use cases for this feature.

65 Likes

Can you change a scriptā€™s RunContext using itself?

Amazing update btw!

12 Likes

What was the most needed use-case for this? This doesnā€™t truthfully seem like a needed thing.

82 Likes

Will there ever be a RunContext that runs the script in both Client and Server.

Iā€™ve had a few occasions where Iā€™ve had to have 2 script do similiar things with slight changes. and just use RunService to modify. Currently the workaround is to just have the Script and Localscript require the same module.

14 Likes

This is exciting, I suppose, but also brings a bit of confusion and worry to my team.

  • Is RunContext meant to replace some LocalScripts?

  • Can you invoke client-only methods by a script with run context set to client?

  • If a script has its run context set to client, does that mean the source of the script will be exposed as well?

  • Whatā€™s the practicality of this feature? Wouldnā€™t this be prone to some sort of exploit?

29 Likes

I anticipate this will bring more problems than it solves as it was perfectly fine before. I donā€™t see any propose or use-case for any of this and Iā€™m a little confused to as why this is added due to the confusion it brings for pretty much everybody.

Thereā€™s also the case to be made that forced organisation of where scripts should be is actually better, because then anyone can hop into a project knowing where everything is.

41 Likes

Awesome update! Two questions:

  • Will there be a built-in LocalScript migration feature?

  • What is the difference between Legacy and Server as of right now? Will there be more differences in the future?

10 Likes

Actors for parallel scripts on clients wonā€™t be restricted to being parented under the character/player anymore. I wonā€™t have to cram them all in one spot anymore.

21 Likes

What is going to happen to scripts running under the ā€œlegacyā€ system once RunContext fully releases?

5 Likes

Your question is already answered inside the post:

11 Likes

It could just be modules inside ReplicatedStorage with a runtime script inside character. Thatā€™s what a ton of people do with for example Knit

5 Likes

The original post mentions a good one.

5 Likes

So this means that LocalScripts arenā€™t needed anymore? I could just pop a script and change its RunContext to client. Does that make any difference from the LocalScripts?

7 Likes

LocalScripts will behave the same as changing a script to client,
FAQ mentioned it.

5 Likes

I am quite confused as to what uses this update as over what was in place. Can I be illucidated?

7 Likes

But this wouldnā€™t be practical and will essentially make module and local script useless. Furthermore, I feel like itā€™ll expose the server itself to potential vulnerability to the server itself such as running server-sided exploits. If my statement stands, it will essentially make knit, arrow, and other dependencies/frameworks useless.

13 Likes

Obviously this isnā€™t an official statement but it appears that one of the biggest use cases for RunContext is to effectively ā€œbundleā€ scripts that work in conjunction with each other. In the example screenshot provided you can see that there is a ModuleScript named SelfieMode, which contains a local script and client script.

image

15 Likes