How do i use other functions in a single function in module script

Hello i want to know if i can use other functions in a single function in module scripts. Like:

local module = require(script.Parent)

local object = module:Create()

object:Unlock()

i saw some people use other functions in a single function. Or maybe i am wrong.

You use the Create() function. After using you get other functions like Unlock, Lock, Callback.

How i do this? I really need it for my module script.

Hopefully i explained very well.

Why don’t you try it and see? (Yes)

1 Like

Is this a joke or what? i’m asking how to do it.

OOP is what you’re probably talking about.

--- ModuleScript
local object_prototype = {}

--- Object Constructor
function object_prototype:new(msg: string?)
    local obj = {message = msg or ""}
    setmetatable(obj, self)
    self.__index = self 
    return obj
end

function object_prototype:method()
    print(self.message)
end

return object_prototype
--- Script
local object = require(the_module_script)

local object_instance = object.new("hi!")
object_instance:method()
1 Like

You’re not getting other functions per-se. What you’re getting is a table that contains functions. This is exactly what module is in the first place:

local a = {}
local b = {}

function a:b()
    return b
end

function b:c()
    print("Hello, world!")
end

a:b():c() --> Hello, world!

That particular instance is an example of object-oriented programming imitation in Luau, and is something far more complex

2 Likes

I hope I’m not late.
I’m not sure but you can try to return a table of fuctions like:

-- Module script
local module = {}

function module:Create()
   -- ur things
   local module2 = {}
   
   function module:Unlock()
      -- script
   end

   return module2
end

return module
--server
local module = require(--[[module path]])

local object = module:Create()

object:Unlock()

My idea was like to create module inside module
I hope you understood what i mean.

1 Like

Kitayumashu, I would highly suggest doing what he said.

I don’t know what OOP is but it actually can be. Thank you for your help

This is a good idea for what i need. I can return the second functions after using the first one. Thank you for your help too.

You’re not late.

Same as Ziffix said, i can return the second functions of a table. Thank you for your help too.

Did I make a mistake while explaining, or did you misunderstand? I just asked how to use other functions inside a function. My English is probably not good enough to explain properly. I’m sorry.

In profile service i can use other functions after using the GetProfileStore function. I need to know how to make this in module scripts.

I used profile service to show this. After getting the Profile Store, I can use other function like LoadProfileAsync(). That’s what i need but i don’t know how i could do this.

Thank you everyone who helped me. Have a good day.

1 Like

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.