Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
✓ ANSWER ACCEPTED

ModuleScript Assets unable to require?

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.

4 comments

0

Have you tested it on a ROBLOX server? Using require() on an assetid will not work within studio.

0

I have tested in a Game Server, however it still doesn't work.

0

I guess you actually can require an asset from studio, though the wiki page on private modules said you couldn't... Anyway, if it didn't print or error then I think there must be something causing your original module to yield for a long time. Does it use the wait function or WaitForChild method on anything before returning?

0

it doesn't use any wait function to yeild

1 answer

✓ Accepted answer

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.

This discussion is preserved as it was. New answers, comments, and votes are closed.