Issues with Modules

I’ve been working on a ‘Tag Game’ and I’ve been working on a modifier system. When I went to test it, it returned an error, ‘Module code did not return exactly one value.’ How do I fix this?

could you post the code please?

Main Module

--// Services
local ReplicatedStorage = game:GetService("ReplicatedStorage")

--// Variables
local GameData = ReplicatedStorage:WaitForChild("GameData")
local ModifiersFolder = GameData:WaitForChild("Modifiers")

local Modifiers = script:WaitForChild("Modifiers")

local module = {}

function module.SelectModifiers(modifierCount) -- Just imagine modifierCount as 1
	
	local modifierTable = {}
	repeat wait()
		
		local modifier = Modifiers:GetChildren()[math.random(1, #Modifiers:GetChildren())]
		if not table.find(modifierTable, modifier.Name) then
			
			table.insert(modifierTable, modifier.Name)
			
		end
		
	until #modifierTable == modifierCount
	
	for _, v in pairs(modifierTable) do
		
		module.ActivateModifier(v)
		
	end
	
end
function module.ActivateModifier(modifierName)
	
	if Modifiers:FindFirstChild(modifierName) then
		
		local modifier = Modifiers[modifierName]:Clone()
		modifier.Parent = ModifiersFolder
		
		require(modifier) -- Error is here!!
		
	end
	
end

return module

You haven’t set anything, you just did require? Maybe you forgot to write the function, because it can’t stay alone without anything, unless it is a local?

Heres the module required code.

-- 2x Speed Module

for _, v in pairs(workspace:GetChildren()) do
	
	if game.Players:FindFirstChild(v.Name) then
		
		v.Humanoid.WalkSpeed *= 2
		
	end
	
end

It doesn’t work like that, you need to set a return. I think you can set it behind the “for”

So, you’re saying I have to add a return to the ‘2x Speed Module’?

Yes, because you not returning everything. A Module Script is built to return something, which in case isn’t and is a normal script that is not working.

1 Like

Thank you so much!!! It worked!

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.