I am creating a system of super powers for the players and there are over 50 of them, each power is its own module inside a folder. The require list was getting very long at the top of the script that calls these powers so I thought about just requiring the module when the player actually uses the power.
The question I have is: Is this a problem? the player will be using these power many times during a play session, and this code will require it each time, is this a problem? A player could be doign require hundred of times each time they play, would this cause a memory leak?
function module:PlayPowerEffects(sentPlayer,sentPower,sentAbility,toggle)
local powerModule = script.PowerEffects:FindFirstChild(sentPower)
if powerModule then
local requiredModule = require(powerModule)
requiredModule:FireAbility(sentPlayer,sentAbility,toggle) -- fire the server side of the power
else
print("ERROR: assigned power doesnt exist")
end
end
As a note, I tried to require all the moduels inside the fodler and require them in a for loop, putting them into a table. But for some reason after doign that I wasnt able to fire and of the methods inside each one, so this was my attempt to simplify things.
this is what my attempt looked like
local powerEffects = {}
for i,v in pairs(script.PowerEffects:GetChildren()) do
powerEffects[v.Name] = require(v)
end
then elsewhere in the script i would try to do this:
powerEffects[sentPower]:FireAbility()
but this would tell me the method didn’t exist, when I’m sure it did
Thanks in advance!