BindableFunctions passing functions

On the Developer Hub on the BindableFunctions page, it notes how:

Functions put in BindableFunctions will not be replicated, therefore making it impossible to use these objects to pass functions between scripts.

To me, this means that I cannot have a function return a function to a BindableFunction, as shown:

Listener:

local bindableFunction = script.Parent.BindableFunction

local function helloWorld()
    print("hello world")
end

local function onInvoke()
    local itemsToReturn = {}
    itemsToReturn.Function = helloWorld
    return itemsToReturn
end

bindableFunction.OnInvoke = onInvoke

Invoker:

local bindableFunction = script.Parent.BindableFunction

local result = bindableFunction:Invoke()
result.Function()

In short, Invoker invokes the BindableFunction to which Listener is listening for and executes onInvoke, which returns the function helloWorld. Based on the Developer Hub, the final line in Invoker should error, either because result.Function is nil (or some other related error).

However, based on my testing, the line above erroring does not happen, and the function executes successfully:

As can be seen in the bottom image, hello world was successfully ran without error when called by Invoker.

Is this intended, and either I’m misinterpreting the Developer Hub’s article or the Developer Hub’s article is out of date; or, is this a bug that I shouldn’t make use of?

I ask this because I’m currently in the process of making my own command system that makes use of this: one script loads all command scripts in a given folder, then listens to a BindableFunction for invocations, returning the command’s function; then a different script actually invokes the function returned by the previous script.

(Here’s a diagram):

(Sidenote, that command system will probably never appear here…because it’s probably full of spaghetti code based on my coding skills, and I’m fairly sure nearly any comptent scripter reading this could make a much better system than mine.)

1 Like

Hi. Use of BindableFunction is rarely needed anymore with the advent of ModuleScripts:
https://developer.roblox.com/en-us/api-reference/class/ModuleScript.
https://education.roblox.com/en-us/resources/intro-to-module-scripts

It may be that limitations mentioned aren’t there anymore due to changes put in
place when ModuleScripts were added.

Also be sure to understand the difference between RemoteFunction and BindableFunction:
https://developer.roblox.com/en-us/api-reference/class/RemoteFunction

Alrighty, thanks for the info.

I’m well aware of ModuleScripts, I use them as a part my command system I’m making that I referenced above. Additionally, I do know the difference between RemoteFunctions and BindableFunctions; my command system trusts the client as little as possible, and uses a RemoteEvent to communicate between the client and server whenever one needs the other to do something.