So there is this block of code I have that is used two times (maybe more in the future) in my scripts, so I decided to make it a module script function. The problem is that one of these blocks of code that I want to make into a function is inside another function in the module script. Can I call a function from a module script from another function in that module script? If so, how?
4 Likes
yes, you can do that. It is the same as in a normal script
If I understand you correctly, yes.
As a simple example, you’d do this:
local module = {}
function module.print(msg)
print(msg .. ", said module.")
end
function module:read(msg1, msg2)
warn("Once upon a time, " .. msg1)
self.print(msg2)
end
return module
Just tested this and it worked:
3 Likes
It doesn’t seem to work for me. Don’t I have to require it or something because it says CopyCardUI is not a valid member of ModuleScript "ServerScriptService.MainModule"
(CopyCardUI is the name of the function I want to call)
That’s probably because you aren’t requiring the module. You’re just referencing the modulescript instance.
1 Like
Ok yeah it works now I had to do this
local Self = require(script)
Self.CopyCardUI()
2 Likes