#How does the module script work?

1 messages · Page 1 of 1 (latest)

alpine jolt
#

i don't know how it works

mortal karma
#

which module script

last coyote
#

So a module script is a script that can be accessed throughout any other script (local and server). A module script is one global table so you can add anything in it. So to add a dictionary amount, here's an example script ( gimme one sec)

#

local module = {}

module.Sword = {
Price = 100,
Name = "Sword",
Level = 1
}

module.SayHello = function()
print("Hello!")
end

return module

#

so, the first thing, module.Sword

#

it is equaled to a table and i can add anything in it!

#

and the second one, i made it a function!

#

so now, if i pull up a server script

#

local module = require(game.ServerScriptService:WaitForChild("ModuleScript"))

print(" The sword costs "..module.Sword.Price.." coins!")

#

this is in a serverscript

#

i called the module script using require

solemn grotto
last coyote
#

and i accessed the price of the sword!

solemn grotto
last coyote
#

so in short, it stores information that can be accessed through server and local scripts!

solemn grotto
#

tsk

last coyote
#

sorry 😭😭

solemn grotto
#

you should be, you're too smart.

#

tsk.. tsk tsk.

last coyote
#

thx!

lilac pilot
# alpine jolt i don't know how it works

a module script is a script that lets u acess/storedata if u wana use it for that if u do the thing Laughingboxes showed u it will store data but the mudle.sayhello is kinda structured in his own way what i would do is
local Self = {}

function Self.PrintHello()
print("hello")
end
--or
function Self.PrintMessage(Message)
print(Message)
end
return Self

proven socketBOT
#

studio** You are now Level 3! **studio

lilac pilot
#

@alpine jolt

#

also how u call it is by doing local Module = require(ur module location.moduleName), how i would is local Module = Require(game.ReplicatedStorage.MyModule)

#

@alpine jolt

surreal nest
#

its really just a storage of values that you can get anything

#

*anytime

#

using the require(modulename) function

lilac pilot
#

not just that u need the directiry

surreal nest
#

dictionary you mean

#

right?

alpine jolt
#

Thank you so much to everyone who explained how it works