RunContext is plugin-editable on LocalScripts, behaves erratically

What’s the problem?
While it’s not visible in the Studio Properties panel, the command bar and Studio plugins can set the RunContext property on LocalScripts, since the property is part of BaseScript, from which LocalScript is also descended, not part of the Script class exclusively.

Why is this a problem?
In Studio tests, Team Test, etc, LocalScripts with RunContext set to Client behave as a Script with Client RunContext would behave in the same situation (which still caused some minor confusion, as it’s not the same as the Legacy behavior for LocalScripts – see here for a similar but unrelated case).

When playing the game via the Roblox player, however, the script will not run at all, instead giving a “blank” error showing only the full name of the script. Since RunContext understandably does not display in the Studio Properties menu for LocalScripts, this creates a really problematic “phantom error” – the error is completely uninformative, the script will appear to work in Studio, and the culprit is not visible by examining the script normally.

Why did you do this?
A coworker of mine, who is not able to report this on their own behalf, ran into this issue accidentally by replacing a Script with a LocalScript using a Studio plugin which allows changing between similar classes while maintaining properties, descendants, etc. You can also reproduce this with Command Bar or a rbxm file, but I’m not sure anyone would run into this by accident without some kind of plugin.

Reproduction files (not mine):

Bug_Repro.rbxl (39.0 KB)

Expected behavior

The developer wiki states the following:

Note, RunContext cannot be used from a LocalScript.

To me this implies that RunContext on a LocalScript should do nothing even if you do set it (Legacy behavior regardless of the applied setting), and should perhaps produce a studio error when you try to change it. Making the behavior consistent between player and studio also seems important; if the preferred behavior is to throw an error at runtime, preferably change the error to something developers can act on rather than just the full name of the problem script with no further elaboration.

4 Likes

I double checked this to make sure, and according to the API RunContext is indeed inherited from BasePart, so silly!!!

As for this, are you saying that a LocalScript with RunContext of Client will behave the exact same as a script with RunContext of client?

Anyway, interesting stuff.

This is actually an inheritance quirk, the fact its hidden on LocalScript should tell you all you need to about intended behaviour here lol

You can set RunContext to Plugin, which has never been implemented for obvious reasons

I kinda already addressed a lot of this in the original post, but just to reiterate / elaborate on the important points:

In Roblox Studio, a LocalScript with RunContext = Client behaves the exact same as a Script with RunContext = Client.
In Roblox Player, the LocalScript instead throws a not-very-informative error and does not run.

(In Player, it actually outputs 2 errors if you put it in StarterPlayerScripts, so it’s still kinda acting like a Script with RunContext = Client, it’s just causing an internal error somewhere between “should this run” and “actually run this”, I guess?)

I know what object-oriented programming is, I understand in a technical sense why the property exists, and that changing it is essentially undefined behavior. But the current behavior is unexpected and needlessly confusing.

(Why was it added to BaseScript when only Script actually uses it? What’s the point? Was it just easier this way? Is it for plugins?)

If you can’t see the property, and it’s not intended to be used, and the documentation says it can’t be used, I’d expect it to do one of the following:

  • Ignore the selected property entirely (always Legacy)
  • Not run the script (silently fail as with Plugin RunContext – preferably not this option)
  • Not run the script (with an error that actually describes the problem)
  • Not allow the property to be changed in the first place (with an error)

As mentioned above, in Studio it does none of these, and it behaves differently in the Roblox Player when published for some reason?

Plugin RunContext, while clearly not intended to be set on Script instances, behaves how I’d expect a non-implemented property to – it makes the script silently not run during Studio test. It’s also harder to set by accident. I don’t think it’s a problem.

2 Likes

Thanks for the report! We’ll follow up when we have an update for you.

3 Likes

Unfortunately this is a side effect of LocalScript inheriting Script but it is not a behavior that we support, hence the property being hidden in Studio. I have made a note of this and we will look at changing this so RunContext for LocalScript is only ever treated as “Legacy”. Thanks for the report.

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.

Hey there! We’ve just rolled out a fix for this issue. Take a moment to check and confirm if everything is working as expected on your end.

Attempting to programmatically set the RunContext property of a LocalScript will now result in a warning being displayed. The value of the property itself will stay fixed to Legacy.

1 Like