Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
✓ ANSWER ACCEPTED

Can you return in a modulescript?

Hi,

I've recently started looking in to module scripts.

I am currently trying to learn returning as well so that I can use this as a replacement to boolValues. (e.g. returning true or false in a module)

Currently as my module code stands:

module.Equip = function(Player, Button, Value, Weapon)
	local Weapon = Button:FindFirstChild(Weapon):Clone()
	Weapon.Parent = Player.Backpack
	return Value
end

The parameter "Value" is set to "true" in the local script that triggers this function.

So basically return Value = return true

I feel like this is the boolvalue equivalent of using a module script.

My problem is I don't understand where this Value is stored. Does it get sent back to the localscript where I can then say

local Equipped = ("Name of Module").Equip() ???

I probably have many misconceptions but I am willing to be pointed in the right direction. Help is appreciated.

1 answer

✓ Accepted answer

ModuleScript

local myFunctions = {}

function myFunctions.Example(x, y)
	local sum = x + y
	
	return sum
end

return myFunctions

Script or LocalScript

local ServerScriptService = game:GetService("ServerScriptService")
local myModule = require(ServerScriptService.ModuleScript)

print(myModule.Example(2, 8)) -- 10

This is an example of how ModuleScripts works. At the end of your function you could return a value and your script that called the function will recieve it. In this case, if you called the function with a variable the value of your variable would become the sum of the two arguments sent. Example:

local mySum = myModule.Example(9, 11)

Now mySum would get the value 20

1 comment

0

please accept his answer if your problem has been fixed.

This discussion is preserved as it was. New answers, comments, and votes are closed.