Hello! I am making a script that runs a game I’m working on, but this piece of code will randomly work, and randomly break upon joining.
for _, module in pairs(pluginsModule:GetChildren()) do
local plugin = require(module)
if type(plugin) == 'function' then
plugin = plugin(_p)
end
_p[module.Name] = plugin
end
Try putting print type(plugin) before your if section to see whether or not it’s the code inside the if statement that’s breaking, or something outside.
It could possibly be because you ran it too soon. Try running the code after everything loads…? From my experience the reason why some things are working but also not working is because you run it too soon. I dont have a direct answer but this should help you probably
wait(2)
for _, module in pairs(pluginsModule:GetChildren()) do
local plugin = require(module)
if type(plugin) == 'function' then
plugin = plugin(_p)
end
_p[module.Name] = plugin
end
@CTGVN123 you should use WaitForChild instead in case of lag that’s over 2 seconds. It will pause the script until the item required is in the workspace or folder it’s supposed to be in.