Module not loading

Hey, Benified4Life here,

Recently I tried to make a custom admin script. I made it in a module Script inside of a script in ServerScriptService. There was no errors and within the past few hours, I was finishing up and doing the final line in the script “require(script.adminCommands)”.

There was no “errors” so to speak, however it said that the requested module experienced an error while loading. I’ve spent a few hours trying to get a fix, (looking through my script to see if there’s any errors, making sure the logic works, etc) however I can’t find anything.

Can I please get some help with this? If you can help it’ll be greatly appreciated. :heart:

This could happen if you have modules attempting to require each other on runtime. Does this sound like it could be happening?

I don’t think so, as the ParentScript only requires the adminCommand script once and the code doesn’t require any other modules.

There should be another error from the offending code. Please post a screenshot of the output

1 Like

Thats my strange output.

That’s weird. Can you set a breakpoint in the module and step through it until it errors? Which line does it break on?

1 Like

I tried that, however, because of the way the script works (It returns the table which holds the commands, functions, etc) I can’t really set breakpoints as it’ll always fire the require function.

Do you mind posting line 2 of the module script

1 Like

I would, except line 2 of the module script is literally just “–Variables”
If you mean of the Parent Script, it’s require(script.adminCommands)

Oh ok I forgot that the error came form the script mb

would putting

local module = {}

at the top, and

return module ={}

at the end of your module make any changes?

I recall getting this error a while back.

Are you returning some type of value from the module? Or do you think you are returning more than one value?

I am returning the table, which holds the functions and commands from the module, but in theory it should work.

As long as your returning one thing, it should work, whether if it is a table, bool, string etc. etc.

Could you post your code? The error resides in the ModuleScript if the requiring script is throwing an error on require.

I would but I just tried and it failed. Miserably failed.

What do you mean? Ctrl + A, Ctrl + C, start a code block and post inside of it.

1 Like

Ah, there we go.



--Variables
local m = {}
local Datastore = game:GetService("DataStoreService")

--Functions
game.Players.PlayerAdded:Connect(function(plr)
	plr.Chatted:Connect(function(msg,r)
		if r then return end
	end)
end)

--Table stuff

m.database = Datastore:GetDataStore("CoolAdminCommands")
m.adminList = {
	41353321;
	-1;
}

m.commandStart=":"

--Checking stuff
local List
pcall(function()
	m.database:GetASync("adminList")
end)
if not List then
	m.database:SetAsync("adminList", m.adminList)
	List = m.adminList
end

--Doing some more stuff
function m.parse(msg,player)
	local playerIsAdmin
	for a,b in pairs(List) do
		playerIsAdmin=b==player.UserId
		if playerIsAdmin then break end
	end
	if playerIsAdmin then
		if msg:sub(1,1)==m.commandStart then
			if #msg==1 then
				print("Just command start you silly goose")
			else
				local line = msg:sub(2,#msg)
				local command, arguments = nil,{}
				for a in line:gmatch("[%w%p]+") do
					if command == nil then command = a else table.insert(arguments,a)
				end
				if m.commands[command] then
					m.commands[command](arguments,player)
				else
				print("No command titled"..command.."exists")
				end
			end
		end
	end
end
end

m.commands = {
	addAdmin = function(arg,caller)
		for a,b in pairs(arg) do
			if tonumber(b) then
				print("Added admin"..b)
				table.insert(List,tonumber(b))
				m.database:SetAsync("adminList", List)
			else
				local userid = game.Players:GetUserIdFromNameAsync()
				if userid then
					print("Added admin"..b)
					table.insert(List,userid)
					m.database:SetAsync("adminList",List)
				else
					m.warn("addAdmin", "Player name \""..b.."\" is not a valid player")
				end
			end
		end
	end;
	
	removeAdmin=function(arg,caller)
		for a,b in pairs(arg) do
			if tonumber(b) then
				print("Added admin"..b)
				for d,c in pairs(List) do
					if c == tonumber(b) then
						table.remove(List,d)
						break
					end
				end
				m.database:SetAsync("adminList",List)
			else
				local userid = game.Players:GetUserIdFromNameAsync()
				if userid then
					for d,c in pairs(List) do
						if c == userid then
							table.remove(List,d)
							break
						end
					end
					m.database:SetAsync("adminList",List)
				else
					m.warn("addAdmin", "Player name \""..b.."\" is not a valid player")
				end
			end
		end
	end;
	print=function(arg,caller)
		for a,b in pairs(arg) do
			print(b)
		end
	end
}


--Even more stuff
function m.warn(cmd, issue)
	print("In command "..m.commandStart..cmd.." issue occured, receipt: "..issue)
end

return m

The issue is somewhere at the top of your script. I threw this code raw into a new place file and tried running it; surely enough, I got the same error. After I began to add prints to the code to set up a form of benchmarks, I noticed that some of the prints were not running. Specifically at the top.

Note: there were a few spelling and conventional mistakes, which I corrected.

The code within the blue square is where the issue is occurring. I haven’t worked towards a solution regarding this chunk yet, though something here is not going as intended. Precisely, it’s refusing to even enter beyond the SetAsync statement.

1 Like

Seems like you have a bit of a spelling issue here.

Corrected:

m.database:GetAsync("adminList") -- Line 25