If you have multiple functions you want a ModuleScript to return. You will need to return a table (due to a ModuleScript only being able to return a single value). Keep in mind that a ModuleScript will only run it's initial code once and will recreate the object it returns every time a script requires the returned value.
Keeping all of this in mind, you could create your initial values at the beginning of the ModuleScript and create an interface that is returned by the ModuleScript for other Scripts to use to manipulate and access those values:
local interface = {}
local number = 3
function interface.arm(WELD)
wlarm = workspace.SomePart
wlarm.C0 = CFrame.Angles(math.rad(WELD[1]),math.rad(WELD[2]),math.rad(WELD[3])) + wlarm.C0.p
end
function interface.setNumber(x)
number = x
end
function interface.getNumber()
return number
end
return interface
Follow Up
That's what I'm confused about. do I have to place local interface = {} and return interface? The model just executes the rotation, the script calling the function is just requesting that the rotation be executed. One more question, if I call two functions right after another in the requesting script. would the second line wait till the first line function has been completed?
What you return is up to you. You can return any value you want as long as you only return a single value (you must return at least one value, even nil will count as a return value). I am simply using this interface as a table to hold multiple functions to be returned.
As for your next question, a thread is responsible for executing code in lua, each Script gets it's own thread and will run it's given code in the order it is given. A function can call multiple functions, whoever the function has to wait for the called function to return before continuing on to the next function call. You can call multiple functions at the same time by creating another thread (lua has a library called coroutine for this reason). Whoever the order in which the functions are called is not explicit. I would highly recommend looking into Lua threads and the coroutine library. They are highly advanced subjects, whoever learning them can be a huge asset.
3 comments
That's what I'm confused about. do I have to place local interface = {} and return interface? The model just executes the rotation, the script calling the function is just requesting that the rotation be executed. One more question, if I call two functions right after another in the requesting script. would the second line wait till the first line function has been completed?
Is there a reason why the local script gives me an error saying numbers isnt indexed and thefore == nil? Im simply writing (Module name).number after I required it.
If you used the code I gave, the interface should not have a number index. You will need to use the getNumber and setNumber to access this number. Also, be sure to use the require function with the module to access its return value. P.S. Sorry about the very late response.