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

Do Modules behave like Scripts?

Asked by 6 years ago

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?

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 ihatecars100 502 — 6y
0
no, theyre different. DinozCreates 1070 — 6y
0
no, its a script to hold code such as settings and functions LoganboyInCO 150 — 6y

2 answers

Log in to vote
0
Answered by 6 years ago

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()
Ad
Log in to vote
0
Answered by 6 years ago

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

Answer this question