Sooo... I have a Bindable Function called GetGamepasses, i want to make it so when i invoke the bindable function with my main script, it triggers another script and makes that script return a table to the main script. The return part wont work for me. Can somebody tell me how i would do that?
How would I return a value through a bindable function?
3 answers
In order to use BindableFunctions, you should understand the purposes for which you should use them. Normally, you would use BindableFunctions when you want to organize your code and expose APIs for other scripts to use. ModuleScripts can also be used for this purpose, but here BindableFunctions are great too.
BindableFunction API dump
The following excerpt is from the API dump. This excerpt tells you the members specific to the BindableFunction class, and from this excerpt you can make an educated guess about how the members, and most importantly the class as a whole, work.
Class BindableFunction : Instance
YieldFunction Tuple BindableFunction:Invoke(Tuple arguments)
Callback Tuple BindableFunction.OnInvoke(Tuple arguments)
Example of BindableFunction Use
As hinted at by the API dump excerpt, BindableFunctions require a callback called OnInvoke to be set. This, as you can probably guess, is what gets called when the Invoke method is called. Below is an example use.
Script 1:
function script.Add.OnInvoke(a, b) -- one way to do it
return a + b
end
function subtract(a, b) -- different way to do it
return a - b
end
script.Subtract.OnInvoke = subtract
Script 2:
a = Script1.Add:Invoke(10, 20)
b = Script1.Subtract:Invoke(20, 10)
print(
Script1.Add:Invoke(
Script1.Subtract:Invoke(a, b),
Script1.Subtract:Invoke(b, a)
)
)
And with that, you know virtually all you need to know about BindableFunction objects!
Why not just use global variables?
In one script:
_G.Table = {
"something", "other value", 1
}
In another:
print(_G.Table[1]) -- something
print(_G.Table[2]) -- other value
print(_G.Table[3]) -- 1
2 comments
Aha, i thought someone would say that... I've tried that before, the script is too complicated so i can't really use them..
What do you mean? Could you show us the code?
yeet truck
This discussion is preserved as it was. New answers, comments, and votes are closed.

2 comments
If you are talking in reference to your last question, you need to use a RemoteFunction, not a BindableFunction.
If not, then please provide some code so we can answer your question correctly.