Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
✓ ANSWER ACCEPTED

How do you use ModuleScripts?

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

✓ Accepted answer

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

2 comments

0

Thanks, man! Now I'll beable to figure them out easier. ;)

0

A ModuleScript doesn't have to return a table.

This discussion is preserved as it was. New answers, comments, and votes are closed.