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?
✓ ANSWER ACCEPTED
What is a Module Script, and when should it be used?
3 answers
✓ Accepted answer
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()
print("Hello")
end
return hi
and then in a normal script:
say_hi = require(Workspace.Test)
say_hi()
It will print "Hello".
1 comment
0
Thanks! This helped so much.
The wiki has an article on module scripts that I believe can answer this question.
More often you'd probably return a table though with multiple functions / variables instead of just one function.
This discussion is preserved as it was. New answers, comments, and votes are closed.

1 comment
Hey there, please remember to mark my answer as accepted if it answered your question.