Problem with modulescript, not sure why it isn't working

So, I’m an experienced programmer, and I don’t know if I’m overlooking this but, I need this function as I’m making admin commands, that loads a version, and it won’t require a proper module. No error in console, everything is in-tact, but the code just won’t work.
No issue with the “settings” variable either.
code:

--AXON ADMIN COMMANDS
--This just inizializes the version, don't change anything unless you're experienced or it might mess it up
local files = {}
local moduleVersion = "0.0.1A"
function initialize(settings)
	print("init")
	local server = script.Versions:FindFirstChild(moduleVersion).Server
	
	server.AxonAdminControl.Parent = game:GetService("ReplicatedStorage")
		print("req")
		
	local sModule = require(server.ServerHandling)(settings)
	print("exe")
	--sModule(settings)-- Execute the server's internal functions, hence, making the system work
	
	
end
function initializeVersion(settings)
	if not settings.Version then settings.Version = 'Latest' end
	
	if settings.Version == 'Latest' then
		local defSettings = require(script.Versions.Latest.Server.DefaultSettings)
		for i,v in pairs(settings) do -- Scan the original settings 
				defSettings[i] = v -- Set the default files line to the variable, (v)
			end
			settings = defSettings  -- set the settings to the default settings
			moduleVersion = settings.Version
			initialize(settings)
			
	else
		if script.Versions:FindFirstChild(settings.Version) then
			local defSettings = require(script.Versions[settings.Version].Server.DefaultSettings)
			for i,v in pairs(settings) do
				defSettings[i] = v
			end
			settings = defSettings
			moduleVersion = settings.Version
			initialize(settings)
			
		else
			warn(string.format("Axon version %s is not available or doesn't exist. Loading latest version", settings.Version))
			local defSettings = require(script.Versions.Latest.Server.DefaultSettings)
			 for i,v in pairs(settings) do -- Scan the original settings 
				defSettings[i] = v -- Set the default files line to the variable, (v)
			end
			settings = defSettings  -- set the settings to the default settings
			moduleVersion = settings.Version
			initialize(settings)
			
		end
	end
	
end
return function(scriptProvided)
	print("prov")
	local settingProv = scriptProvided.Settings
	settingProv.Parent = script
	scriptProvided:Destroy()
	script.Parent = game:GetService("ServerScriptService")
	initializeVersion(require(settingProv))
	
	
	
end

Can you show the script that requires this one? The issue might be there.

It returns a function, should work. Here’s the code for returning it
p.s, it fails when it requires it

function initLoading(csettings)
	print("yes")
	--local versionFolder = script.Parent.Parent
	settings = csettings;
	pluginApi = Instance.new("BindableFunction")
	pluginApi.Name = "axonPluginAPI"
	pluginApi.Parent = rep
	players.PlayerAdded:Connect(function(p)
		print("you")
		api.addLog(sysTable.joinLogs, string.format("%s:%s", p.Name, p.UserId))
		local banInfo = dataHandling:GetData(p.UserId, "Bans")
		if banInfo then 
			p:Kick(string.format("AXON: %s. Reason: %s", settings.BanReason, banInfo.Reason or "No reason provided"))
			return
		end
		if api.isUserBanned(p.UserId) then
			p:Kick("AXON: ".. settings.BanReason)
			return
		end
		if sysTable.serverLocked then
			if not api.isStaff(p.UserId) then
				p:Kick(settings.ServerLockReason)
			end 
		end
		print("you2")
		p.Chatted:Connect(function(msg)
			printMes(p.Name.. " said "..msg)
		local isCmd = api.getPrefix(msg)
		if isCmd == settings.Prefix then
			if settings.PublicCommands then
			api.ProcessMessage(p, msg)
			else
				if api.isStaff(p.UserId) then
					api.processMessage(p, msg)
				end
			end
		elseif isCmd == '!' then
			if msg:lower() == '!help' and settings.HelpEnabled then
				api.RequestModerationHelp(p)
			end
		end
		
		end)
	end)
	
	
end
return initLoading

Sorry if I was unclear, I meant the non-module script that requires the original module. (Just the line(s) leading up to where you require it and call the function it returns)

The code from the original post is called from a normal script, that calls the serverhandling module, that handles everything, it prints until it reaches “print(‘req’)”(from the initialize function)

function initialize(settings)
	print("init")
	local server = script.Versions:FindFirstChild(moduleVersion).Server
	
	server.AxonAdminControl.Parent = game:GetService("ReplicatedStorage")
		print("req")
		
	local sModule = require(server.ServerHandling) -- wont work past this point
	print("exe") -- wont print
	--sModule(settings)-- Execute the server's internal functions, hence, making the system work
	
	
end

That is irrelevant. It works perfectly, except the fact it won’t be called. I posted the end of the function above.
Here:

function initLoading(csettings)
	print("yes")
	--local versionFolder = script.Parent.Parent
	settings = csettings;
	pluginApi = Instance.new("BindableFunction")
	pluginApi.Name = "axonPluginAPI"
	pluginApi.Parent = rep
	players.PlayerAdded:Connect(function(p)
		print("you")
		api.addLog(sysTable.joinLogs, string.format("%s:%s", p.Name, p.UserId))
		local banInfo = dataHandling:GetData(p.UserId, "Bans")
		if banInfo then 
			p:Kick(string.format("AXON: %s. Reason: %s", settings.BanReason, banInfo.Reason or "No reason provided"))
			return
		end
		if api.isUserBanned(p.UserId) then
			p:Kick("AXON: ".. settings.BanReason)
			return
		end
		if sysTable.serverLocked then
			if not api.isStaff(p.UserId) then
				p:Kick(settings.ServerLockReason)
			end 
		end
		print("you2")
		p.Chatted:Connect(function(msg)
			printMes(p.Name.. " said "..msg)
		local isCmd = api.getPrefix(msg)
		if isCmd == settings.Prefix then
			if settings.PublicCommands then
			api.ProcessMessage(p, msg)
			else
				if api.isStaff(p.UserId) then
					api.processMessage(p, msg)
				end
			end
		elseif isCmd == '!' then
			if msg:lower() == '!help' and settings.HelpEnabled then
				api.RequestModerationHelp(p)
			end
		end
		
		end)
	end)
	
	
end
return initLoading

That’s really strange. Does “req” print? If you change it to require(server.ServerHandling)(settings) does it work or print “prov”?

I saw this line (7), and I’m a little confused, what is rep supposed to be? This would theoretically be the equivalent of parenting to nil?

Similarly with api (line 10)

rep = replicatedstorage, sorry for that confusion, the api.addlog is working, and shouldn’t effect the module. Before addlog is called, it won’t even print what I want it to, that is the word “yes” as a placeholder.

1 Like

looks like a big fat yield. are you requiring both modules in the same module?

example:

module A:
local b = require(a)

module B:
local a = require(b)

had this happen to me before, could be a possibility

i think it happens because of it requiring over and over (i think ok)

1 Like

Have you tried commenting everything out of your initLoading function except the print("yes") part and seeing if that prints? If it does, there is probably some kind of weird error that lua is frustratingly not telling you about in the module.

I apologize, I made a mistake in the command module and waited for a event that doesn’t get called until after the function, and it waits until it does, and it won’t work till it finds it. I’ve corrected this, I deeply apologize. Thank you for your help.

3 Likes