What is a module ID?

  1. What do you want to achieve? I have seen models like CheckMeIn and others use a module script with require() and a bunch of numbers inside

  2. What is the issue? I don’t know what a module IS is and how to find it

  3. What solutions have you tried so far? I have looked on the developer hub and it doesn’t mention numbers anywhere just require(scriptpostion)

Thanks for reading! :smile:

1 Like

modul is library, it is script, that cant execute and by

local modul = require(--[[modul path]])

you create var modul, that can execute the functions, and what is very useful: you can edit value in modul by 1 script and read the edited value by another script
edit:
example:

local m = require(--[[path]])
print(m:someMathOperation(1,8))

module:

local module = {}
function module:someMathOperation (x,y) 
{
return x/y*100
}
return module

I’d suggest reading on it and watching YouTube tutorials. They’re basically json files

A ModuleScript is a special type of script that is meant to be used by other scripts. It does not run on its own, and instead will run when the require() function is used on it from another script.

When it runs like this, it returns a value of any type (table, bool, string, number, object), which is useful for doing things like creating your own library (essentially a table with functions inside it):

-- let's say you want to add more features to the default `math` library
-- by making your own version of it and calling it `CustomMath`

local CustomMath = require(script.CustomMathModule)

print(CustomMath.Add(10, 12)) -- outputs 22

The CustomMathModule itself might look like this:

local CustomMath = {}

CustomMath.Add = function(a, b)
   return a + b
end

return CustomMath

An easy way to imagine ModuleScripts is that they are just normal functions, except you run them using require(module) instead of functionName(), and they must return a single value (return true is valid, but having no return or doing return 1, 2 with multiple return values is invalid).

Normally in Roblox you require a module by giving the ModuleScript object itself, for example require(script.Parent.ModuleScript). However you can also require ModuleScripts that are uploaded to Roblox as Models by using the ID of the model: require(12345678).

3 Likes

Not quite. JSON is for transmitting data as human-readable text through key-value pairs. ModuleScripts are code fragments that run only when required (lazy loading) and support any valid Lua or Roblox datatype. They also must return a value to the script that required it - nil is also a valid return.

Yea. I just realised easier. I’ve been using them like jsons and not for small snippets of code. I’m going to do some reading on it today