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) |
2 | local events = game.ReplicatedStorage:FindFirstChild( "Events" ) |
3 |
4 | events.Animations.OnServerInvoke = function (player) |
5 | local module = require( 980963185 ) |
6 | return module |
7 | end |
1 | -- ModuleScript 'B' (located in game.ReplicatedStorage) |
2 | local module = game.ReplicatedStorage.Events.Animations:InvokeServer() |
3 |
4 | return module |
1 | -- LocalScript 'C' (located in game.StarterPack) |
2 | local ninmodule = require(game.ReplicatedStorage.ModuleScript) |
3 | ninmodule.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?
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
1 | local _m = { } --mirror right here |
2 | function _m.printsomething() |
3 | print ( "yo" ) |
4 | end |
5 | return _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.
1 | local module = require(game.ReplicatedStorage.ModuleScript) |
2 | --now to simply call the function inside the module |
3 | module.printsomething() |
Simple as that.