Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

[Solved]: How to get Data Back from Module Script?

Asked by 2 years ago
Edited 2 years ago

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.

1 answer

Log in to vote
1
Answered by 2 years ago
Edited 2 years ago

Return

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.

0
thank you for the reply. it will help me in future projects thx! Hi_People1133 218 — 2y
Ad

Answer this question