Hello,
When i was working with Modules lately, I attempted to upload the ModuleScript
to the ROBLOX Site, therefore allowing the usage of private modules. However when i renamed the ModuleScript
to 'MainModule' and updated it to the site as a model, as i tried to require
the module using its assetid. My original code isn't as simple as this, but it still failed to work like the following.
Here is a code example of the situation:
Inside the ModuleScript
local test = {} function test:add(x, y) return x + y end return test
Inside the Script
local library = require(378772246) -- This is the assetId of the module print(library:add(1,2)) -- It didn't print anything or error in the output
Edit:
I have placed the script in ServerScriptService
.when the module is placed in-game and required,
the function fired, but not from an asset.
From my knowledge and experiences, I believe that requiring a module by it asset ID only work on a live server. Meaning both play solo and test server will not work.
I remembered that I had too upload the the module to the place while testing.
A easy way around this is to either do as I said. Upload the module and remove when done.
local Module = require(Workspace.Module) --require(00000)
Or do what I like to do is load the module with InsertService.
Another note that you should keep in mind that users are allow to require lock module and it is very easy to see the source of them. I done it before.
Loading a module using InsertService is prob as secure as it get.