Need quick clarification about PlayerScripts and ModuleScripts within it

Hi everyone,

I have 2 folders in my StarterPlayerScripts, one which contains some utility ModuleScripts, and another which contains a few LocalScripts that require these modules. I want to make sure I get no errors when I run these LocalScripts in PlayerScripts, so I’d like to make sure I understand exactly what happens when a player joins the game.

After ReplicatedFirst is replicated to client and the game snapshot is loaded, then the LocalScripts/ModuleScripts in StarterPlayerScripts are copied into PlayerScripts, and once all of them are copied, then the scripts start running? So I can assume all of my modules are present in PlayerScripts when the LocalScripts start running? Please let me know if I am misunderstanding this part.

Assuming this is the case, should I require the ModuleScripts from PlayerScripts, or could I also require them from their original form in StarterPlayerScripts? Which is better?

Thanks a bunch!

1 Like

The process in which a client starts their game is roughly this:

  • ReplicatedFirst any objects inside of itself as a container, while also executing any code found in any LocalScripts inside of itself.
  • (I would assume) next, as part of general replication, StarterPlayerScripts will have any objects as descendants under them replicated to the client - if they’re LocalScripts, they will also have their code ran.

Because StarterPlayerScripts is a kind of container, so as to say it’s basically a Folder but with special purposes, it still acts kind of like a Folder. This is why you can have lots of modules inside of a Folder inside of ReplicatedStorage, and only need to use WaitForChild on that folder once in order to know you can require all of the modules inside and know that they’ve been replicated.

In short, you should be fine to require modules in StarterPlayerScripts and not need to wait if you’re requiring your modules from a LocalScript that’s a descendant of StarterPlayerScripts.

On the flip side, if you were to require your modules in StarterPlayerScripts (they would then only be accessible as a descendant of the Player) from ReplicatedFirst, because ReplicatedFirst sees the absolute first objects that are replicated to a client, you would have to use WaitForChild for those modules to be present.

Hope this cleared things up.

3 Likes