Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

How to require "MainModule" from the client?

Asked by 7 years ago

Recently, I found out that using Module scripts allows me to protect my work from clients till the script is complete. One problem occurred when trying to require a MainModule script from the client because it won't allow you to use the 'require()' on the client. After fiddling with RemoteEvents, I've finally ended up with a method to require a module from the client.

After solving that problem, I figured out that it will not work when running it in-game.

1-- ServerScript 'A' (located in game.ServerScriptService)
2local events = game.ReplicatedStorage:FindFirstChild("Events")
3 
4events.Animations.OnServerInvoke = function(player)
5    local module = require(980963185)
6    return module
7end
1-- ModuleScript 'B' (located in game.ReplicatedStorage)
2local module = game.ReplicatedStorage.Events.Animations:InvokeServer()
3 
4return module
1-- LocalScript 'C' (located in game.StarterPack)
2local ninmodule = require(game.ReplicatedStorage.ModuleScript)
3ninmodule.Animations()

The result from running the script is as follows:

1-- Players.Player1.Backpack.[S] Animations:4: attempt to call field 'Animations' (a nil value)
2-- Stack Begin
3-- Script 'Players.Player1.Backpack.[S] Animations', Line 4
4-- Stack End

Is there any solution on how to call the module function from the client with Filtering-Enabled on?

0
Heads up: You can't pass functions from the server to the client (and vice-versa) through Remotes. Arrays, Dictionaries, and Instances are OK, however. XAXA 1569 — 7y

1 answer

Log in to vote
0
Answered by 7 years ago

Well, I'm not quite sure on what you're asking for. But this may help:

firstly, we need to be sure that the module is wired to a mirror, so that you can call it in scripts.

ex: THIS IS THE MODULE SCRIPT

1local _m = {} --mirror right here
2function _m.printsomething()
3    print("yo")
4end
5return _m

Now to link this module to a client, or a script would be done like this.

ex: THIS IS THE CLIENT, OR A SCRIPT THAT YOU ARE WIRING.

1local module = require(game.ReplicatedStorage.ModuleScript)
2--now to simply call the function inside the module
3module.printsomething()

Simple as that.

0
I am aware of this method, however, is there any way for the client to require a MainModule? The require() is server-only while Filtering Enabled is on. Ninjaruaz 22 — 7y
0
Well I do believe you don't HAVE to use require but I don't really mess with modules. Albino_Albino 0 — 7y
0
require() isn't server-only when filtering is on... XAXA 1569 — 7y
Ad

Answer this question