Is it possible to call functions from other scripts?

just what the title says. is it possible to call functions from other scripts? is there any way to do it? no matter how difficult or easy is it possible?
I know this is probably really simple but i am new to lua

2 Likes

There’s two clear ways I know of: ModuleScripts and BindableFunctions.
You can fire a BindableEvent and have other scripts listen to that event. BindableFunctions are similar, but the syntax is a little different and they return a value like a function would.

Meanwhile, ModuleScripts are basically just tables with values and functions in them. For example:

local myModule = {}

myModule.value = "Hello World!"

function myModule.printValue()
    print(myModule.value)
end

return myModule

And then in a script:

local myModule = require(pth.to.myModule)

myModule.printValue() -- "Hello World!"
print(myModule.value) -- "Hello World!"

Obviously you can tell which one is my favourite.

4 Likes