"Requested Module Experienced an Error while loading."?

Hello! I am making a game and a certain module is stopping the rest of the script from working, here’s the module:

local COLOSSEUM_ID = 6793467878
local RESORT_ID    = 6793468987

if game.CreatorId == 1084073 then
	COLOSSEUM_ID = 313771763
	RESORT_ID    = 314437797
end

local storage = game:GetService('ServerStorage')
local subContextStorage = storage:WaitForChild('SubContexts')
local repStorage = game:GetService('ReplicatedStorage')
local placeId = game.PlaceId
local context

if placeId == COLOSSEUM_ID or game:GetService('RunService'):IsStudio() then
	context = 'battle'
	storage.MapChunks:ClearAllChildren()
	storage.Indoors:ClearAllChildren()
	subContextStorage.Colosseum.Skybox.Parent = game:GetService('Lighting')
	local worldModel = subContextStorage.Colosseum.WorldModel
	worldModel.Parent = workspace
	pcall(function() require(script['2v2Board']):enable(worldModel['2v2Board'].Screen.SurfaceGui.Container) end)
	pcall(function() require(script.SpectateBoard):enable(worldModel.SpectateBoard.Screen.SurfaceGui.Container) end)
	local chunk = subContextStorage.Colosseum.chunk
	chunk.Name = 'colosseum'
	chunk.Parent = storage.MapChunks

	storage.Models.BattleScenes:ClearAllChildren()
	subContextStorage.Colosseum.SingleFields.Parent = storage.Models.BattleScenes
	subContextStorage.Colosseum.DoubleFields.Parent = storage.Models.BattleScenes

	subContextStorage:Destroy()
	game:GetService('Lighting').TimeOfDay = '14:00:00'
elseif placeId == RESORT_ID then
	context = 'trade'
	storage.MapChunks:ClearAllChildren()
	storage.Indoors:ClearAllChildren()
	subContextStorage.Resort.Skybox.Parent = game:GetService('Lighting')
	subContextStorage.Resort.WorldModel.Parent = workspace
	local chunk = subContextStorage.Resort.chunk
	chunk.Name = 'resort'
	chunk.Parent = storage.MapChunks

	--	repStorage.Models.BattleScenes:Destroy()

	subContextStorage:Destroy()
	game:GetService('Lighting').TimeOfDay = '20:00:00'--'14:00:00'
else
	context = 'adventure'
	subContextStorage:Destroy()
end

if context ~= 'adventure' then
	game:GetService('Players').ChildAdded:connect(function(player)
		if not player or not player:IsA('Player') then return end
		if player.UserId < 1 then
			player:Kick()
		end
	end)
end

local tag = Instance.new('StringValue')
tag.Name = 'GameContext'
tag.Value = context
tag.Parent = repStorage.Version

return context

Anything wrong with this module? Why is it saying “Requested Module Experienced and Error While Loading”?

What line does this happen on, and is there more output?

There is no output of the module other than “Requested Module Experienced an Error While Loading”, I don’t know if I will be able to locate the line the error occurs, but I will try.

What was the tactic? debug.traceback(), It is a joke, but maybe it can help you solving this, as my tired eyes can’t see the answer.

1 Like

Huh, it could be the wrapped in pcall’s, for some reason.

I altered the code a bit, mostly by adding a ton of :WaitForChild() and :FindFirstChild() arguments, to prevent any infinite yields, and I tested the pcall issue by commenting the pcalls and that did not work. here is the new code:

wait(.5)
local storage = game:GetService('ServerStorage')
local subContextStorage = storage:WaitForChild('SubContexts')

local COLOSSEUM_ID = storage:WaitForChild("ColloseumID").Value
local RESORT_ID    = storage:WaitForChild("ResortID").Value

local placeId = game.PlaceId
local context

if placeId == COLOSSEUM_ID or game:GetService('RunService'):IsStudio() then
	context = 'battle'
	
	--Clear Chunks
	storage:WaitForChild("MapChunks"):ClearAllChildren()
	storage:WaitForChild("Indoors"):ClearAllChildren()
	
	--Unpacker
	subContextStorage:WaitForChild("Colosseum"):FindFirstChild("Skybox").Parent = game:GetService('Lighting')
	local worldModel = subContextStorage:WaitForChild("Colosseum"):FindFirstChild("WorldModel")
	worldModel.Parent = workspace
	
	pcall(function() require(script['2v2Board']):enable(worldModel['2v2Board']:WaitForChild("Screen"):FindFirstChild("SurfaceGui"):FindFirstChild("Container")) end)
	pcall(function() require(script.SpectateBoard):enable(worldModel:WaitForChild("SpectateBoard"):FindFirstChild("Screen"):FindFirstChild("SurfaceGui"):FindFirstChild("Container")) end)
	
	local chunk = subContextStorage:WaitForChild("Colosseum"):FindFirstChild("chunk")
	chunk.Name = 'colosseum'
	chunk.Parent = storage:WaitForChild("MapChunks")
	
	storage:WaitForChild("Models"):FindFirstChild("BattleScenes"):ClearAllChildren()
	subContextStorage:WaitForChild("Colosseum"):FindFirstChild("SingleFields").Parent = storage:WaitForChild("Models"):FindFirstChild("BattleScenes")
	subContextStorage:WaitForChild("Colosseum"):FindFirstChild("DoubleFields").Parent = storage:WaitForChild("Models"):FindFirstChild("BattleScenes")
	
	subContextStorage:remove()
	game:GetService('Lighting').TimeOfDay = '14:00:00'
elseif placeId == RESORT_ID then
	context = 'trade'
	
	--Clear Chunks
	storage:WaitForChild("MapChunks"):ClearAllChildren()
	storage:WaitForChild("Indoors"):ClearAllChildren()
	
	--Unpacker
	subContextStorage:WaitForChild("Resort"):FindFirstChild("Skybox").Parent = game:GetService('Lighting')
	subContextStorage:WaitForChild("Resort"):FindFirstChild("WorldModel").Parent = workspace
	local chunk = subContextStorage:WaitForChild("Resort"):FindFirstChild("chunk")
	chunk.Name = 'resort'
	chunk.Parent = storage:WaitForChild("MapChunks")
	
	subContextStorage:remove()
	game:GetService('Lighting').TimeOfDay = '20:00:00'--'14:00:00'
else
	context = 'adventure'
	subContextStorage:remove()
end

if context ~= 'adventure' then
	game:GetService('Players').ChildAdded:connect(function(player)
		if not player or not player:IsA('Player') then return end
		if player.UserId < 1 then
			player:Kick()
		end
	end)
end

local repStorage = game:GetService('ReplicatedStorage')
local tag = Instance.new('StringValue')
tag.Name = 'GameContext'
tag.Value = context
tag.Parent = repStorage:FindFirstChild("Version")

return context

Really not anything different, just a ton of :WaitForChild()'s, do you have any ideas on how I could find the exact location of what’s causing the issue?

Wait, this is the wrong module, I’ve been reading the output very wrong. Sorry for the confusion! I think I know how to fix this now!

1 Like

I dont see local context = {} on the top of your module script, module script use the following layout

local module = {}

return module

Do you know that isn’t needed?

Good job! It is good for you, and for us too hshshs.

Good afternoon, body.

Can I see the script where you require the module?

Usually when modules fail to require there is a second error message indicating why it failed (eg. module does not return exactly one value, or a logic error with your script’s source). Do you see anything like that?

image

1 Like

I do, that is actually how I fixed it earlier, forgot to mention it here. Everything works now, but thank you all for your time!

1 Like