I deleted this post character limit

I deleted this post character limit

Here, please use the search bar for this.
require is bascially getting the returned value from a ModuleScript.
The int64 value in the require is the model id, it’s the model in that model id is a ModuleScript named MainModule, it’ll require that ModuleScript.

-- ModuleScript
local module = { };

function module.sum(a, b)
    return a + b;

return module;
-- Script/LocalScript
local module = require(ModuleScript);
print(module.sum(1, 2)); --> 3

It’s like asking what does #include do in C or what does import do in Python.



Require is a function (which is also an entity/element within the _G table), require requires a module/a valid module script AssetId(considering it is a model) in order to proceed/access it’s contents.

So next time you want to load module scripts into a script or local script or even another module script then be sure to use require.

It has a good use, write only once and use it everywhere.

If you need more information, or further help, perhaps even detailed then please reply.

Upvote and mark this a solution if you gained new knowledge and if it helped.

— Parceni

1 Like

This is for vanilla Lua, not Roblox Lua, these a difference between those two.

The same concept, the question was “what does require do” not “what’s Roblox require”.

Isn’t it obvious the OP meant the Roblox Lua version? Just because the title was “what does require do” that doesn’t mean it applies to vanilla Lua.
dofile doesn’t exist on Roblox Lua, and you cannot use require on “files” on Roblox Lua.
Roblox Lua require only accepts integral values (Roblox Model id) or a ModuleScript.


This is a ROBLOX developer forum, not a Lua forum. I don’t think he’d care about vanilla as he’s probably here to make and script Roblox games.

Some aspects still apply, I’ll update the answer in order to fulfill the OP’s need. Thanks for pointing that out.

Alright, sounds good to me. Keep developing :heart:

It’s to call a module script, if there are numbers it’s most likely that the ModuleScript is published to Roblox and running while it not being in game.

1 Like