Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
COMMUNITY QUESTION

Help with ModuleScripts. Two different errors?

16:30:51.061 - Module code did not return exactly one value 16:30:51.063 - Requested module experienced an error while loading

Where I require the scripts:

role = require(table.remove(roles, math.random(#roles)))

One of my roles (they are all the same):

local Role = require(game.ServerScriptService.Roles.defRole)()

Role.ID = "Cop";
Role.Ability = "Investigate one player per night.";
Role.Attributes = "Vote for one player at night. The next day you get a hint of the player's role."
Role.Alignment = "town";
Role.Meetings = {"inves", "lynch"};
Role.Items = {}

return Role

The defRole:

return function()
	local Role = {
	ID = "";
	Ability = "";
	Attributes = "";
	Alignment = "";
	Meeting = {};
	Items = {}
	}
	
	Role.canKill = function(gameObject, target, reason)
		return true
	end
	
	Role.onKill = function(gameObject, target, reason)
    	Role.defaultOnKill(gameObject, target, reason)
	end
	
	Role.defaultOnKill = function(gameObject, target, reason)
		local char = target.Character
		if char then
			char:BreakJoints()
			wait(5)
			char:Destroy()
		end
	end
	
	
	return Role
end

Not sure why this is happening, if anyone has any input I would be highly appreciative.

1 answer

If you put the scripts you've provided in a blank place, they do not error.

The first error message occurs when a ModuleScript attempts to return multiple things, like return 1, 2, OR when a ModuleScript doesn't return anything (interestingly, you can return nil, but you cannot just say return). You'll have to inspect the full error for the script and line number where it happens - that'll be the require statement that required the ModuleScript that's at fault.

The second error message, "Requested module experienced an error while loading", always happens when you require from a ModuleScript that errors. Just fix the first one and this one will disappear.

This discussion is preserved as it was. New answers, comments, and votes are closed.