How to stop Requested module was required recursively

Hello! I am Dev_Asher and I am working on a consumable system, but now I am getting the error Requested module was required recursively on the main module I have that stores all of the data. How would I fix this?

local Players = game:GetService('Players')

local ReplicatedStorage = game:GetService('ReplicatedStorage')
local ReplicatedModules = require(ReplicatedStorage:WaitForChild('Modules'))
local ReplicatedCore = require(ReplicatedStorage:WaitForChild('Core'))

local SettingsModule = ReplicatedModules.Settings
local AssetService = ReplicatedModules.AssetService

local PingTimesModule = ReplicatedCore.PingTimes
local SystemsContainer = {  }

local ConsumableDebounce = {  }

local ConsumableFunction = { 
	WeakRedPotion = function(LocalPlayer, Profile)
		local Humanoid = LocalPlayer.Character and not LocalPlayer.Character:FindFirstChildOfClass('Humanoid')
		if Humanoid then
			SystemsContainer.EffectService:RunAnimation(Humanoid, SettingsModule.CharacterAnimations.PotionDrink, Humanoid, LocalPlayer)
			task.delay(0.5 - PingTimesModule[LocalPlayer], function()
				SystemsContainer.EffectService:HealPlayer(Humanoid, 20)
		return (Humanoid ~= nil)

local print = function(...)

local warn = function(...)

local Module = {}

function Module:OnCooldown(LocalPlayer, CooldownName)
	if not ConsumableDebounce[LocalPlayer] then
		ConsumableDebounce[LocalPlayer] = {  }

	if (ConsumableDebounce[LocalPlayer][CooldownName]) and (ConsumableDebounce[LocalPlayer][CooldownName] - os.clock() > 0) then
		return  true
	return false

function Module:ApplyConsumable(LocalPlayer, consumableUUID)

	local profile = SystemsContainer.DataService:GetPlayerProfile(LocalPlayer)
	if not profile then
		return false

	local itemData, index = ReplicatedModules.Settings:GetItemFromInventoryByUUID(profile.Data.Inventory, consumableUUID)
	if not itemData or itemData.Quantity == 0 then
		if itemData.Quantity == 0 then
			table.remove(profile.Data.Inventory, index)
		return false
	local itemConfig = ReplicatedModules.Settings:GetItemConfig(itemData.ID)
	if (not itemConfig) or (not itemConfig.Tags.Consumable) then
		warn('No Consumable Config Found For Item of ID: '..itemData.ID)
	local consumableTagID = itemConfig.ID
	local func = ConsumableFunction[itemConfig.Tags.Consumable.ID]
	if not func then
		warn('No Consumable Function Found For Item of ID: '..itemData.ID..' Of '..consumableTagID)
		return false
	if Module:OnCooldown(LocalPlayer, 'PrimaryActive') then
		print('PrimaryActive: ', ConsumableDebounce[LocalPlayer].PrimaryActive - os.clock())
		return false
	if Module:OnCooldown(LocalPlayer, itemConfig.Tags.Consumable.ID) then
		print(consumableTagID..': '..ConsumableDebounce[LocalPlayer][consumableTagID] - os.clock())
		return false
	ConsumableDebounce[LocalPlayer].PrimaryActive = os.clock() + itemConfig.Tags.Consumable.AcivationDuration
	ConsumableDebounce[LocalPlayer][consumableTagID] = os.clock() + itemConfig.Tags.Consumable.CooldownDuration
	itemData.Quantity -= 1
	if itemData.Quantity == 0 then
		table.remove(profile.Data.Inventory, index)
	local result = false
	local sucsess, err = pcall(function()
		result = func(LocalPlayer, profile)
	if not sucsess then
	return result

function Module:Init( otherSystems )

	SystemsContainer = otherSystems
		ConsumableDebounce[LocalPlayer] = nil


return Module

Can you send the full error so I can see what exactly is erroring?
Requested module was required recursively on the main module means that the module is calling itself over and over again in a loop so it won’t finish loading.

I fixed it sorry for the trouble, I wish you a great day or night :smiley:

“Requested module was required recursively” means exactly what it says.

It means that one of your ModuleScripts is trying to load a module that’s trying to load the current module.
For example, your Core module might be requiring the data module (the module whose code you posted). I don’t know what’s requiring what, but that’s what it means.

Take a pen and paper.
Draw something representing your main module.
For each module your main module requires, draw a new thing, and draw an arrow from the new thing to your main module.
Repeat with each new module found: check what each of them is requiring (first look whether it’s already on the paper) and draw an arrow from the required module to the requiring module.
Because you’re getting this error, you should see a cycle somewhere on the paper.

1 Like

No trouble at all! I am glad you got it sorted.