Idk what’s going on.
The ModuleScript:
--Variables
local Config = require(script.KronosConfig)
local Assets = game.ServerStorage:WaitForChild("KronosAscended_ServerStorage")
local Admins = Config.Council_Members
--main
local Main = {}
--AddGui
Main.AddGui = function(player)
local newGui = Assets["GUI's"].MainGui
print(player)
end
return Main
The Script that requires it:
Ascended = game.Workspace.KronosAscended
Handler = Ascended.Main:WaitForChild("KronosHandler")
game.Players.PlayerAdded:Connect(function(player)
print("PLAYER_ADDED")
require(Handler.Main.AddGui(player))
end)
The error I get is “Main is not a valid member of modulescript.”
1 Like
When you require a ModuleScript
, it’s run. If it returns a value, then that’s what you get from it.
-- MyModule.lua
return "Hello world!"
local returningValue = require(script.MyModule)
print(returningValue) -- Output: Hello world!
I believe you’re trying to return a table called Main
, you can access the table by doing something like this.
local Main = require(script.Handler) -- change this to the path of the 'Handler' module
Now, to integrate it with your script, you’d want to do:
Note: I made the variables local
. For more info on that, feel free to check out the DevForum thread here.
local Ascended = game.Workspace.KronosAscended
local Handler = require(Ascended.Main:WaitForChild("KronosHandler"))
game.Players.PlayerAdded:Connect(function(player)
print("PLAYER_ADDED")
Main.AddGui(player)
end)
@OptimisticSide, Wouldn’t doing that run KronosHandler when I require it, because I only want it to run when I do “Main.AddGui(player)
”
The error says “Main” doesn’t exist yet, consider adding
Ascended:WaitForChild(“Main”)
Edit:
Misread it, sorry
Ok, thank you for the response!
No. If you require it the module scirpt is ran. BUT the function is not. Whatever your modulescript returns is returned. In this case Main
is returned. So you have to do this.
Ascended = game.Workspace.KronosAscended
Handler = require(Ascended.Main:WaitForChild("KronosHandler"))
game.Players.PlayerAdded:Connect(function(player)
print("PLAYER_ADDED")
require(Handler.AddGui(player))
end)
The error means: You tried to access a property or child of the ModuleScript Instance
that doesn’t exist
That makes much more sense, thank you!