Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

How do you use ModuleScripts?

Asked by 10 years ago

I've seen them being used before, and when I try to make my own, it never works. How can I set up or make one?

1 answer

Log in to vote
0
Answered by
ked2000 15
10 years ago

Basically, a modulescript doesn't operate by itself. Think of it as a library. You must have a separate script(not modulescript) that utilizes it.

The way a modulescript works is interesting. Though I won't go into that, you should learn more about it. Just know that for every module script, you must a table that contains everything in the module script and return it.

Here's an example:

ModuleScript:

local lib = {}

function lib.sayHi()
    print("Hi")
end

return lib

Script:

local myModule = require(workspace.ModuleScript)
myModule.sayHi()

Output:

Hi

0
Thanks, man! Now I'll beable to figure them out easier. ;) TheeDeathCaster 2368 — 10y
0
A ModuleScript doesn't have to return a table. Articulating 1335 — 10y
Ad

Answer this question