How do I send parameters between a module script and a regular script?

Im trying to send a value to a module script, so how can I do that?

Are you familiar with how functions work? The same applies in this case.

1 Like

You seem to want to require(modulescript) with arguments?

You’ll have to make the modulescript return a function and then call that function.

So if you had a module like this:

local variable = "world"

print("Hello " .. variable .. "!")

return {}

then you’ll have to make it return a function that uses the arguments.

return function(variable)
	print("Hello " .. variable .. "!")
end
-- one line
require(modulescript)("world")

-- many lines
local greet = require(modulescript)
greet("world")
5 Likes

If Im being honest, I don’t understand most of what your saying. Can you maybe put more comments across the code?

I don’t see why you would want to pull a value into a module script, but you can do that by either:
1.) Store a Value object with the data you want to nab in the module script
2.) Fetch another module script containing functions that return your data (preferably calculated).

The first is pretty simple, create a Value and store it somewhere the module script can access it

The second is also pretty simple, just set up module script 1

local module1 = {}

module1.func = function()
-- do stuff
end

return module1

And call it into module script 2

local module2 = {}

module2.callMod1 = function()
local Mod1Funcs = require(game.ServerScriptService.Module1)
local MyVariable = Mod1Funcs.func()
-- do stuff
end

return module2

Edit:
I can elaborate more on what that all means if you need me to.

Say, what are you trying to make?

1 Like