Return something from a module script as args

So what I’m trying to do is return arguments from a module script,

for example; here’s my creation script

tab1:NewDragBar("test",30,function()
	
end)

Now in the function() part I want it to use an argument from the module script, i may not sound too clear here so let me explain further.

I want to return

local val = 100; --or whatever the value ends up being

From the module script so that you can use it as an argument in the function in the main script; is this actually even possible?

EDITED (exanded example) @rokasalmonaitis1.

Well, you have multiple ways to achieve this. One way is to require a module script and use the data inside. We can do that because module scripts are formed as a table that is returned as the final statement.

-- Module script:
local module = {}

-- This value is private and is accessible to module script only.
local otherValue = 50

-- This value is available when your require the module.
module.yourValue = 100

return module

-- Server script:
local module = require(script.ModuleScript)
local yourValue = module.yourValue

-- The following is written with preposition that value is already rapidly
-- being changed in the module script.

-- Example 1:
for i = 1, 10 do
	print(yourValue) -- prints same stored value
	wait(1)
end

-- Example 2:
for i = 1, 10 do
	print(module.yourValue) -- prints updated values
	wait(1)
end
4 Likes

You can also have the module return a function rather than a table.

There’s many methods to use module script to return values. Either you use a simple require() or variable it with a function, although these are easily replacable by writing them in the main script.