How do I use the `require` code correctly?

Alright so I decided I would start helping some of my friends but I don’t want to take the chance of them stealing my stuff and giving them to others.

Is there a way to use the require command for normal scripts and if not, what can I do to in replace of it?

What I am attempting to do is have it where people can’t steal my scripts while still being allowed to use my scripts. A good example, a lighting script I have… I want to let my other friends use it but I don’t want them to steal it or edit it. What are my options?

I have viewed the Developer site and Q & A sites and I haven’t really found much on it.

1 Like

Require(…)

Is only for the use of Module Scripts

When, you require you are essentially grabbing or fetching a module scripts(they are very handy (: )

This issue here is that, Allowing someone to use your code, but not allowing them from stealing is pretty hard(to my knowledge) using roblox, along with this, I believe there is no clear cut way of checking if a player has edited your code either.

This is a resource that might give you some more insight:

Hopefully this was helpful in some sort of way!

3 Likes

Hide it in a bunch of empty models, folders, and other stuff and hope they won’t find it?
Do plant in decoys too to confuse them :evil:
Many malicious scripts work that way, so it makes it hard to find. You wont have to use require at all. Just write your code from the scope of the hidden script.

6 Likes

store a ModuleScript inside of ReplicatedStorage.

Inside of StarterPlayerScripts, insert a localscript that makes the modulescript a global variable, then rename and destroy the ModuleScript AND call script:Destroy() so it’s harder to trace back to the ModuleScript.

Then, in every script that uses the ModuleScript to function (besides the server), use require(_G.modulescriptvariable). Below is an example on how I secure my ClientModule.

wait()
if not _G.soup then
	_G.soup = game:GetService("ReplicatedStorage"):FindFirstChild("ClientFramework")
end
if _G.soup then
	local ooga = game:GetService("ReplicatedStorage"):FindFirstChild("ClientFramework")
	ooga.Name = "salads"
	ooga:Destroy()
	script:Destroy()
end
script:Destroy()

Hope this helped. It makes the ClientModule accessible without having the risk of it being stolen. I know that there are better methods out there, but this is the one that I personally use.

I believe they were looking for ModuleScripts that would not allow other developers to see its source as compared to players not being able to see the source.


To answer the OP:

With the current powers that Roblox has given us right now, it is not directly possible to create closed-sourced modules in Studio. This feature was removed after a series of malicious scripts were found on the website. However, there are third-party resources available to you (some linked by a previous poster).

Please note, however, that if you use a third-party closed module system, the host (reator of the third party service) holds all rights to the scripts that you store on their systems and are able to release it at any given point regardless of your permission. That means that while it is closed to the rest of your players and developers, the creator of the third-party service will always be able to access your scripts and Roblox will have no power in aiding you if your scripts are leaked.

4 Likes

require() is only used for ModuleScripts, meaning you should publish a Module (if you know how to use them) to the ROBLOX website, then get the ID of it. After you do that, you can send this code to a friend:
require(1234567890)
It should be very simple.

3 Likes

Remember to rename the ModuleScript to MainModule before publishing, otherwise you will be unable to require by its asset id.

1 Like

TLDR; Roblox’s built-in module system does not allow to make it closed-source anymore. That means, even if you ask your friend to use require, they will still be able to see your module script and what’s inside.

So what happens if you’re making the module script that you uploaded become private? The script simply won’t work, the require becomes useless.

More info here:

2 Likes

This should be very helpful, helped me learn modules too.
well , not going in much complexity you can use modules to share functions like for example, create a module called functions, keep it in ServerScriptService .Next create a regular serverscript parented to it, (for demonstration)
like this
image
then in the module do something like :

local functions = {}

   --function storage, convenient

 function functions.prints()
	print("1 worked")
end

    function functions.go()
	   print("2 works too")
end




return functions --exactly one value is returned as you can see

in the script :

local functions = require(script.Parent)--requiring the module, receiving the values i.e functions

functions.prints()
functions.go()

just for people new to module scripts, but in your case, your module can only be required from you asset id if you’ve published it , make it private, that’ll prevent others from requiring it in their scripts

2 Likes

Another alternate way of returning multiple functions through one module:

ModuleScript

function blah() 
    print("blah") 
end

function blargh() 
    print("blargh")
end

return {blah, blargh} 

Script

blah, blargh = unpack(require(ModuleScript)) 

blah() - - prints blah
blargh() - - prints blargh

I would recommend @XxELECTROFUSIONxX 's method though, as it is more practical.

2 Likes

You can use obfuscator so no one can steal your encoding and edit it.

2 Likes