How to add arguments to function in module

Recently I have been having issues where requiring a module by id does not seem to allow arguments in functions.

Module:

local module = {}

function module.func(a, b)
   print(a, b)
end

function module.thing()
   return "hello"
end

return module

Script:

local module = require(id)

local hello = module.thing() -- returns "hello"
module.func("a", "b") -- attempt to call a nil value

What can I do about this?

1 Like

I’d try printing a line when you require the module

local module = require(id)

if module then
    print("Test")
end

Then I’d try different values for the arguments, like a number or variable stored on the script.
If it’s attempting to call a nil value for just the string value, then it’s indicating that string values might not be able to be passed to a module script.

This doesnt seem to be the issue as putting the module in the script that requires it and replacing require(id) with require(script.ModuleScript) gives no errors. Both of the functions work and “a b” gets printed.

You need to publish the module with the id everytime you make an edit f you want it to work.

Nevermind I guess? This somehow didnt work yesterday, I had the module up to date and named MainModule, so I have no idea why it wouldnt work.

But today I changed my code back and its working now??

Maybe I just needed to restart studio, no idea

1 Like