My aim is to organize my library better by separating my module script into multiple different scripts which will be referenced by calling module.submodule.function(). The submodule would be a module script inside the module script. This is what it would look like in the explorer:
At the moment inside the main module my code looks like this to test:
local Main = {
["Sub"] = script.Sub
}
return Main
The code in the sub module looks like this:
local Sub = {}
function Sub.Say()
print("Hello")
end
return Sub
Then I call the module from a server script using this code:
local Module = require(game:GetService("ReplicatedStorage"):WaitForChild("Main"))
Module.Sub.Say()
However the error Iâm getting in the console is this:
15:34:18.937 Say is not a valid member of ModuleScript âReplicatedStorage.Main.Subâ - Server - Script:3
Thanks for taking your time to read. Help is appreciated.
From what youâve shown above, it does not look like you have something called âSubâ inside that module.
It looks like you have something called âSubmoduleâ and not âSubâ.
Also be aware doing this will make it extremely difficult to browse through your module and find how a function works.
The method i use instead looks something like this:
do --Connect stuff to events
local E = yata yata
E.Something.YataYata.OnServerEvent:Connect(etc. etc.)
end
do --Other stuff
--More stuff here
end
do --More stuff
--stuff
end
And you can have do end sections inside do end sections.