For example, considering the following code is inside a ModuleScript:
local RemoteEvent = Instance.new("RemoteEvent", game.Workspace) RemoteEvent.OnServerEvent:Connect(function() print("Hello") end)
Will it print "Hello" when I call :FireServer() on the RemoteEvent?
Yes, as long as you require()
the ModuleScript
from a server script.
A ModuleScript
cannot run without another script calling require()
on it. Once it happens, it runs on the same peer it was required from.
So if you require it from a LocalScript
, it will act like a localscript, meaning you can access LocalPlayer
, FireServer()
, etc.
However if you require it from a server script, it will act like a server script, meaning you can use OnServerEvent
event and replicate stuff to all clients.
(Note when I say "act like a __ script", I don't mean stuff such as lack of Disabled
property in ModuleScripts)