Introduction
Private modules are created by naming a ModuleScript "MainModule", and uploading it to your user profile. Once the script has been uploaded, the name that it appears under on the site can be called anything.
They're called private modules because you can require them using their asset Id, rather than using the directory that leads right to it's source. Because of this, a request does have to be sent to ROBLOX to retrieve the information, meaning you can only preform this action directly from the server (using a server script, opposed to using a local script), and there will be a fraction of a second delay (though that's negligable).
Protecting your source code
As the ROBLOX wiki mentions, it's very easy to steal the source code of a private module, despite it being "private".
"How is the source code stolen?"
If there is any way the user can access the global environment of your module, your source code can be stolen with ease. Luckily, there are a few really easy ways to prevent this. For example, if somebody has access to the global script variable within your module, they can simply execute this code: print(env.script.LinkedSource) in the command bar or any other program authorized to use protected features such as LinkedSource.
I'd go more into detail about how to prevent this, but the wiki explains it pretty substantially here: http://wiki.roblox.com/index.php?title=Private_module
Using private modules
Anyway, once you've uploaded your module making sure it follows all the requiements to use it, you can just require the asset Id (remember this can only be done server-sided). Here's an example:
Module uploaded
local module = {}
function module:printname()
print(script.Name)
end
return module
Script that requires the module
local module = require(145987531)
module:printname()
And that's about it. Hope this helped, if you have any questions, just let me know.
3 comments
This helped me out +1 for ya
how do i unhide it XD
Just a small update, you can also use nested modules or use the main module you're requiring as some sort of interface for your bulk code.