RunContext Scripts have Unexpected Behavior

Attached below is the original post (Now closed)
https://devforum.roblox.com/t/scripts-with-runcontext-to-client-have-unexpected-behavior-when-parented-to-starterplayerscripts/2400152/4

The main problem is that scripts with RunContext of Client runs in SPS (StarterPlayerScripts), and is cloned into PS (PlayerScripts) to run there as well. I dont know if this is a feature that has always existed or has only just been added with the RunContext feature, but the observed behavior is the following:

  • LocalScripts do not run in SPS but are cloned into PS and run there.
  • Scripts with RunContext of Legacy do NOT run in SPS but are cloned into PS and do NOT run there either.
  • Scripts with RunContext of Client run in SPS and are also cloned into PS and run there.

I would say this is not intended behavior as this is the documentation of RunContext:

A script with RunContext of Client should either not be cloned into PS and run in SPS, or should be cloned into PS and not run in SPS.
A script with RunContext of Legacy should behave exactly like a script with RunContext of Server.

StudioRunContextTest.rbxl (42.4 KB)

3 Likes

The point of RunContext is to have only a single script, so this is perfectly accurate behavior. It is kind of odd how they didn’t deprecate local scripts and make the script object with client run content have almost identical behavior.

1 Like

You should not put RunContext = client scripts in StarterPlayerScripts. They’re designed to be placed in ReplicatedStorage or workspace alongside the content or libraries they interact with.

LocalScripts are still required for some supported workflows like Tools, hence the lack of deprecation.

5 Likes

What I like to do is I like to utilize the studio Run feature to test as it loads much faster. For an effect script that would be handled on the client, would I be better off placing that script with RunContext of client into ReplicatedStorage as I wouldn’t have to worry about strange behavior like the cloning in StarterPlayerScripts?

Upon further inspection, I’ve noticed that the cloning behavior seen in SPS is not limited to scripts. I still can’t fully wrap my head around why scripts with RunContext of Legacy dont run in SPS or PS, while they Client or Server variants run in SPS and PS, however this may reflect old behavior I had not observed.

Going to mark this topic as solved.

If you do something similar (this method helps me with debugging as Running is faster than PlayTesting), I recommend just using scripts with RunContext of client which are parented into ReplicatedStorage.

1 Like

That was indeed the old behavior.

We wanted the new RunContexts to be entirely consistent: RunContext = Server always runs on the server, regardless of location, and RunContext = Client always runs on the client regardless of location.

It can be a little counterintuitive right now when blended with various legacy workflows like StarterPlayer, but we decided having very simple to explain / understand behavior going forwards was more important than having exceptions.

2 Likes

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