Questions on RunContext and OOP

With the release of RunContext, I just have some questions regarding OOP.

I have a project where I need server side scripts alongside local scripts in replicated storage or workspace. However, most my server sided logic is in module scripts through OOP.

Since my project is meant to be like a ‘package’ as mentioned in the RunContext post above, I need my module scripts with my server scripts and not in Server Storage.

This raises a few questions though:

Is it safe to have module scripts alongside local scripts?

Does the modules not being required by a local script prevent them from being replicated?

Can the client read my server logic through my modules?

I’d appreciate any explanations, thank you for your time.

1 Like

If the ModuleScripts are anywhere the client can see them, no

No; the ModuleScript would have to be somewhere in ServerScriptService or ServerStorage to not be replicated

Any changes the server makes in the ModuleScript won’t replicate to the client (if that’s what you’re asking)

2 Likes

Thanks for the response, I appreciate it.

How about in the case the module script is parented to a server side script? Is it still replicated?

If the modules are replicated, is there any point in RunContext since replicating sever logic would be unsafe wouldn’t it?

Sorry, I meant read the code itself and see how the game works.

1 Like

Yes

RunContext just changes the way that scripts execute (for example, a Script with a Client RunContext can run in ReplicatedStorage or Workspace by default and still function like a LocalScript, whereas legacy LocalScripts can’t run under those services).

TL;DR RunContext doesn’t affect the way that ModuleScripts are replicated, so there’s no point in using it for that purpose

In that case, yes

1 Like

Marked @HugeCoolboy2007 as solution but would still be open to more discussion on OOP projects and RunContext.

All of the instances themselves will be replicated to the client however the source replicates differently depending on the RunContext and instance type.

  • ModuleScript - Source always replicates
  • LocalScript - Source always replicates
  • Script - Source replicates when RunContext is set to Client

Therefore, any ModuleScript instances you use will have their source accessible to clients. While a bit of a hack you could bypass this by having a server script inside of the ModuleScript that actually sets up the interface but this will mean things such as typechecking won’t be available for that module.

We are aware of this use-case though and there have been some discussions about server only modules. If you have any feedback or use-cases you want to share definitely let me know!

2 Likes

Ah okay. I appreciate the response and clarification.

I’ll definitely look out for this in the future then!

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