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

How to use a private module?

Asked by 8 years ago

I understand that you can use private modules to keep your scripts hidden from other Roblox users. I already have a script I want to put in a private module. I just don't understand how to use private modules.

I have looked it up on the internet, on Roblox's Youtube channel, and the wiki yet I cannot find anything on it. Could you guys please help me get started on this?

1 answer

Log in to vote
1
Answered by 8 years ago

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 = {}

-- Just prints the name of the module when called
function module:printname()
    print(script.Name)
end

return module

Script that requires the module

local module = require(145987531) -- Arbitrary number, but this would be where the asset Id goes.

module:printname() -- This would print "MainModule", since that's what you must name it in order to use private modules, and that's what the code inside the method yields.

And that's about it. Hope this helped, if you have any questions, just let me know.

0
This helped me out +1 for ya SinsofFallenGods 50 — 7y
0
how do i unhide it XD JohnnyTheGamer_YT -17 — 6y
0
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. ScriptGuider 5640 — 6y
Ad

Answer this question