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)
end)
end
return (Humanoid ~= nil)
end,
}
local print = function(...)
--print(...)
end
local warn = function(...)
--warn(...)
end
local Module = {}
function Module:OnCooldown(LocalPlayer, CooldownName)
if not ConsumableDebounce[LocalPlayer] then
ConsumableDebounce[LocalPlayer] = { }
end
if (ConsumableDebounce[LocalPlayer][CooldownName]) and (ConsumableDebounce[LocalPlayer][CooldownName] - os.clock() > 0) then
return true
end
return false
end
function Module:ApplyConsumable(LocalPlayer, consumableUUID)
local profile = SystemsContainer.DataService:GetPlayerProfile(LocalPlayer)
if not profile then
return false
end
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)
end
return false
end
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)
end
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
end
if Module:OnCooldown(LocalPlayer, 'PrimaryActive') then
print('PrimaryActive: ', ConsumableDebounce[LocalPlayer].PrimaryActive - os.clock())
return false
end
if Module:OnCooldown(LocalPlayer, itemConfig.Tags.Consumable.ID) then
print(consumableTagID..': '..ConsumableDebounce[LocalPlayer][consumableTagID] - os.clock())
return false
end
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)
end
local result = false
local sucsess, err = pcall(function()
result = func(LocalPlayer, profile)
end)
if not sucsess then
warn(err)
end
return result
end
function Module:Init( otherSystems )
SystemsContainer = otherSystems
Players.PlayerRemoving:Connect(function(LocalPlayer)
ConsumableDebounce[LocalPlayer] = nil
end)
end
return Module