Log in to vote

What is a Module Script, and when should it be used? [closed]

Asked by
Bolohuc 255
3 years ago

ROBLOX recently added a new object, "ModuleScript," to the Basic Objects window in studio. How does it work? What is it? When should I use the new object?

Hey there, please remember to mark my answer as accepted if it answered your question. User#11893 55 — 3y

Locked by ConnorVIII and Articulating

This question has been locked to preserve its current state and prevent spam and unwanted comments and answers.


Looks like you're using an ad blocker.

That's fine...

No, it really is.

Just, I mean, we put a lot of work into this site, you know?

It would be really really appreciated if you would turn off your ad blocker for our website...

We tried really hard to make our ads as unobtrusive as possible.

If you really hate ads, would you consider a $2 donation via Patreon?

Here's the link.

We love you. We hope you love us too.




Now back to your regularly scheduled Scripting Helpers....




3 answers

Log in to vote
Answered by 3 years ago

A ModuleScript is an instance that mimics the built-in module system of Lua. You can imagine a ModuleScript as one big function that returns a value. In a normal script, you can use the require function which will return the value that the module script returns.

For example, if in a module script "Test" you have:

function hi()

return hi

and then in a normal script:

say_hi = require(Workspace.Test)

It will print "Hello".

Thanks! This helped so much. Bolohuc 255 — 3y
Log in to vote
Answered by 3 years ago

The wiki has an article on module scripts that I believe can answer this question.

Log in to vote
Answered by
Ekkoh 605
2 years ago

More often you'd probably return a table though with multiple functions / variables instead of just one function.