Placement guide
| Requirement | Location |
|---|---|
| Server and client scripts both require the module | ReplicatedStorage |
| Only server scripts require the module | ServerScriptService |
| A server ModuleScript is stored with other server-only objects | ServerStorage |
ServerScriptService contains server-only scripting objects, including ModuleScripts required by server scripts, and its contents are never replicated to clients. ServerStorage also contains server-only objects. Scripts do not run while parented there, but scripts in ServerScriptService can access and run ModuleScripts stored there.
Keep trusted logic on the server
Because clients receive the contents of ReplicatedStorage, it is not a private location. Keep server-only logic in a server-only container. Roblox also requires the server to validate data sent by clients before using it.
How require() behaves
A ModuleScript runs once when first required and returns the same reference to later require() calls in the same environment. When the same ModuleScript is required on both sides of the client-server boundary, it returns a unique reference for each side.
Roblox identifies WaitForChild() as an important safety measure when client scripts access replicated objects:
Code: Select all
local ReplicatedStorage = game:GetService("ReplicatedStorage")
local SharedModule = require(ReplicatedStorage:WaitForChild("SharedModule"))Use ReplicatedStorage for modules intentionally shared with clients, ServerScriptService for server-only scripting logic, and ServerStorage when a server ModuleScript is kept with other server-only stored objects.