Defining Modules

Hey, gonna keep this short & simple but how can I define modules…
This is what I’m working with

image

image

and I can define it in “hub” & the UIS I wanna keep the same format like I have currently but in a working way.

You define them like this:

local Dragger = require(modulescript directory here)

what I assume you want:

local Dragger = require(script.Lib.Dragger)

Now you can access the functions and variables inside of it

1 Like

Hmm I see
How would I access everything in it?
image
so I can make it work with certain frames buttons etc…

Looking at the way you have your script set up, I assume your module script looks something like this:

local module = {}

function module.new(frame) -- creates a function named "new" in the "module" table
   -- code in here

   -- example code:
   print(frame.Name) --> "Frame" (assuming that's the name)
end

return module

Basically, to access things in a module script, it depends on what’s being returned.

In this example, the table named module is being returned so everything that’s in that table is accessible from the script that required it.

-- example script
local moduleScript = require(script.Parent.ModuleScript) -- the module script

-- since the module script returned the "module" table, I can access the contents of it
moduleScript.new(script.Parent.Frame) -- you would access things in a module script the same way you would access things in a normal table (depending on what's returned) 
-- the function "new" would use the parameter the script sent

It looks like this:

local module = {
    new = function(frame)
       -- code
    end
}

module.new(script.Parent.Frame)

Err, I’m not really understanding I’m not gonna a various amount of modules,

image

Here is the main script as I haven’t really started anything yet. image

All of the modules that have been added already have been finished and tested so I know they work the Smooth Dragging, Fading in and out, and Tweening.

Here is another example of an open-source Admin System

I’m trying to replicate something like that in a way