Hello Dear Scripter,
I was creating A math module script. I sent data to them through functions Parameters to the module. What i need is the Number Back from the module script. How do i do that?
Module Script
local Math = {} function Math.Add(Number1, Number2) local NewNumber = Number1 + Number2 end function Math.Sub(Number1, Number2) local NewNumber = Number1 - Number2 end function Math.Multiply(Number1, Number2) local NewNumber = Number1 * Number2 end function Math.Divide(Number1, Number2) local NewNumber = Number1 / Number2 end return Math
Normal Script
local MathData = require(script.ModuleScript) Number1 = 40 Number2 = 20 MathData.Add(Number1,Number2) -- How do i get data Back from module???
I need help, or even give me some suggestions,
fell free to ask questions,
Bye.
Just use the return
statement. This exits a function's execution context with a given result or list of results. Example:
In Module
local Math = {} function Math.Add(num1, num2) local sum = num1 + num2 return sum -- return the result end return Math
Outside Module
local Math = require(script.ModuleScript) local result = Math.Add(5, 10) print(result) -- > 15
Let me know if you have any questions.