I have this script in which I load a configuration script when an item is equipped. The module is contained inside the item. When one rapidly switches tools, it spits the error: Attempted to call require with invalid argument(s). I believe this is because the modules do not load inside, is this possible? And how would I fix this? Tool equip cooldowns don’t work because to have the cooldown work it uneuips after equipping, which means it still try’s to load the module.
Any help is appreciated.
Thanks, - Lukas
1 Like
Hi Lukas,
Could you provide an excerpt of the code where you’re requiring the module scripts? It’s hard to get a good sense of what may be causing your error without some context.
At first glance though, I would be surprised if that error was caused specifically by the quick switching between tools. If that is the case though, you could investigate loading the module into the script at the beginning of its runtime instead of upon equip.
Best,
Speedy
1 Like
The specific code in question:
for _, Item in pairs(Player.Backpack:GetChildren()) do
local Connection
Item.Equipped:Connect(function()
local Config = require(Item:FindFirstChild("Config", true)) -- The true at the end means that the program will look through all descendants to find, not just immediate.
The error is pointing to line 35, the last line shown here. (The require)
1 Like
Do all of the tools in the game have a “Config” module within them? If not, the FindFirstChild
would return nil
for tools without a Config module, and cause the error you’re seeing by calling require(nil)
.
1 Like
Yes, they do.
Sorry for the late response.