Help with modules

This is my first time posting and I’m a very new dev so sorry if I did something wrong with this post

  1. Is it possible for a module to have the same functions as a child module. For example ExampleModule:ExampleFunction() instead of ExampleModule.ChildModule:ExampleFunction()
  2. How would I achieve this?
  3. I’ve tried looking on the dev forum for a post similar to this and I could not find one but maybe that’s a issue with my phrasing. I’ve also tried setting the module equal to the parent.
1 Like

What do you exactly mean by child module?

Like for example:

1.ReplicatedStorage
   2. Module --(Child of ReplicatedStorage) 
        3. ChildModule --(Child of Module) 

Yes like
1.ReplicatedStorage
2. Module --(Child of ReplicatedStorage)
3. ChildModule --(Child of Module)

Okay so in this case

local RS = game:GetService("ReplicatedStorage") 

local Module = require(RS.Module) 
local ChildModule = require(RS.Module.ChildModule) 

Module:Example() 
ChildModule:Example() 
local Module = {}

function Module:Example() 
print("Hey I am Module") 
end

return Module
local ChildModule = {}

function ChildModule:Example() 
print("Hey I am Child Module") 
end

return ChildModule

No no I’m looking more for the two modules sharing the same functions instead of two modules with different functions. I was watching Davidii’s stream and he had local DungeonFeature = Class:Extend() instead of what I usually thought modules had which would be like DungeonFeature = {} so I thought that there was one main module that contains the functions of all the children as the function was called Extend or something like that

But why would you do that if you have the function in the main Module already?

no no like I think it was for organization as having all the functions in one module would lead to super long modules but he still wants to access all the children’s module functions from one module

Oh I maybe get you know.

You can just require the Parent module?

local ChildModule = {}
local Module = require(script.Parent) 

Module:Example() 

return ChildModule

oh I don’t know why I didn’t think about that, thanks.

Don’t worry if you have anymore questions don’t be afraid to post them because ModuleScripts are actually quite interesting thing :D.

Wait actually I have realized that what you did would be calling the function and not writing the function

Hm… but why would you need to rewrite the function? The purpose of ModuleScript is to have something like “shared” things that you can use outside of the ModuleScript.