"Module code did not return exactly one value"

Hello!

I tried looking around the forum but I can’t find what I’m looking for. Basically, I get the error that “Module code did not return exactly one value” and nothing else. I can’t find the source of it and I have no idea how to proceed.

It’s literally just that, nothing else. Any ideas?

3 Likes

This means that your ModuleScript returned 2 or more values, in other words your ModuleScript attempted to return a tuple, ModuleScripts can only return a single value, typically a table value containing all of the features of the ModuleScript itself.

1 Like

Yes, but I don’t know what module is the source. I have probably at least a hundred module scripts.

Also, it can also happen if no values are returned. Nothing seems to be breaking either, it just seems like an exasperating, useless error message.

Shouldn’t clicking on it lead to the source module?

- modulescript

return 'bla', 'bla'

will make 2 errors

  1. requested module experienced an error
  2. module did not return exactly one value
1 Like

Only solution I can think of is pressing Ctrl + Shift + F, type “return” and manually look through module scripts to see which one(s) return multiple values/no values.

1 Like

I thought so too, the error message isn’t clickable.

@p49p0, only one error message was shown in the output.

Figured the issue out, basically I iterated through all descendants where module scripts are located, attempted to require them with a pcall, and if it wasn’t successful it outputted a print, 2 separate loops because of an error that the array was too long to unpack, this should work though.

Lazily written, ignore horrible variable names:

for i,v in pairs({unpack(game.ReplicatedStorage:GetDescendants()); unpack(game.StarterGui:GetDescendants())}) do 
	if v:IsA('ModuleScript') then 
		coroutine.wrap(function()
			local s,e = pcall(require, v) 
			if not s then
				print(e,v)
			end 
		end)()
	end 
end

for i,v in pairs(workspace:GetDescendants()) do 
	if v:IsA('ModuleScript') then 
		coroutine.wrap(function()
			local s,e = pcall(require, v) 
			if not s then
				print(e,v)
			end 
		end)()
	end 
end
7 Likes