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

Do Modules behave like Scripts?

So, I put my script in my a module, I played the game. The module didn't execute, so I redid the recalled the function. So, is module just additional adding recall to the function? Or they're just 2 different things?

3 comments

0

well, basically you just have to do require(module) and you can do some custom functions and events that can be shared between server and client

0

no, theyre different.

0

no, its a script to hold code such as settings and functions

2 answers

modules work like a place to hold your code for later use try this example:

module:

local mod = {}


function mod:Test()-- must include the name of your local up above ^^

print("test worked")
end

return mod--must be same as local

regular script:

require(script.Parent.mod):Test()

module scriupts work like a global function: here is what i mean.

in module

local module = {} -- declares an object

module.sayHello() = function()
	print("Hello there good sir!")
end

return module

so the above declares an object variable in a module script named: module and then I give the object - module- a property named: sayHello

and then we return the whole object

here is another depiction:

local module = {
	sayHello = function()
		print("Hello good sir")
	end

} -- declares an object


return module

sayHello is basically a variable of module. now to call this global function - Module- we need to require() it. require is a function that is intended to be for getting modules in Scripts, Localscripts, - and even Module script-

In Server Script

local module = require(game.Workspace....) --<- this takes an Argument of the path of the target  module 

module.sayHello() -- since it returns the table, we can just access its properties
-- the above calls the function we fed to the module

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