Help with returning a Embedded function

You can write your topic however you want, but you need to answer these questions:

  1. What do you want to achieve? I want to return a embedded function

  2. What is the issue? Include screenshots / videos if possible! I’m unsure how to return a embedded function

  3. What solutions have you tried so far? Look on google for help and the form and found no answers

After that, you should include more details if you have any. Try to make your topic as descriptive as possible, so that it’s easier for people to help you!

function BasicMath()
    function Add(a,b)
        function Subtract(a,b)
            function Mutiply(a,b)
                function Divide(a,b)
                    end
                end
            end
        end
    end

Hello there! i’m trying to return a embedded function how can i do this? thanks for your help :slight_smile:

use return

local function hi()
   local otherFunctions = {}
   otherFunctions.Bye = function()
      return "Bye!!"
   end
   return otherFunctions
end

print(hi().Bye()) -- prints "Bye!!"

If you want to chain a function then take a look at this post:

function GetFunction()
   return function(a, b)
   end
end

Just to provide context for @iGottic’s response, this would be syntax for returning nested functions:

function embed()
	return function(a,b)
		return function(c)
			return (a*b)+c
		end
	end
end

embed()(1,2)(5)
-- 7
1 Like
-- ModuleScript in ReplicatedStorage

local basicMaths = {}

basicMaths.Add = function(a, b)
    return a + b
end

basicMaths.Subtract = function(a, b)
    return a - b
end

basicMaths.Mutiply = function(a, b)
    return a * b
end

basicMaths.Divide = function(a, b)
    return a / b
end

return basicMaths

-- Script in ServerScriptService

local basicMaths = require(game.ReplicatedStorage.ModuleScript)

local value = basicMaths.Add(69, 420)
print(value)