I want to import a ModuleScript using the require function. The problem is, the ModuleScript is in ServerScriptService, which is only accessible by server scripts. I would like to use the module inside my LocalScript but I can't access it, so I thought RemoteFunctions would provide me with a way to still retrieve the module but I'm not sure how I would go about doing that. I'd appreciate any feedback, and thank you!
✓ ANSWER ACCEPTED
How do RemoteFunctions work?
1 answer
✓ Accepted answer
As DataStore said, you can just put the ModuleScript in ReplicatedStorage and require it from there.
Additionally, if you rename the ModuleScript to "MainModule" and upload it to ROBLOX as a Model, you can require the asset ID of that model (the string of numbers at the end of the URL) from both LocalScripts and Scripts.
To actually answer your question, here is the syntax for RemoteFunctions:
--Script (ServerScriptService)
local func = Instance.new("RemoteFunction", Game.ReplicatedStorage)
func.Name = "Remote"
func.OnServerInvoke = function(source, message) --OnServerInvoke is a method of the RemoteFunction that can be set to a function by the user, in contrast to other methods such as Destroy and Clone.
--The first parameter here, source, is the Player associated with the Client peer that called the InvokeServer method of the RemoteFunction from a LocalScript, as you'll see below.
print(source.Name .. " sent a message: " .. message)
func:InvokeClient(source) --The first argument is the Player to receive the Invocation of the RemoteFunction. This method will call the OnClientInvoke method of the RemoteFunction on the given Player's client.
end
--LocalScript (StarterGui, runs in a Player's PlayerGui)
local func = Game.ReplicatedStorage:WaitForChild("Remote")
func.OnClientInvoke = function() --Note the lack of the parameter supplied when invoking the Client.
print("Server received the message!")
end
func:InvokeServer("I'm the scatman!") --Again, note the lack of the first argument. Both are assumed to be the LocalPlayer; that is, the Player attached to the client the LocalScript is running on.
Comment on this answer if you have any questions.
1 comment
0
Thank you!
This discussion is preserved as it was. New answers, comments, and votes are closed.

2 comments
Why not just put the ModuleScript in ReplicatedStorage, or somewhere similar?
You could also just pass the AssetId of the ModuleScript to require.