Bindable Events and Functions - What are they good for?

I understand how Bindable events and functions work. I also understand how to use Module scripts. My question is

“Is there a specific situation or scenario where using Bindable events and functions is the best solution for a coding problem? And why? “.

Any examples would be greatly appreciated:)

The main use case I have for bindable functions is to communicate between 2 module scripts, without having a recursive requiring() thing happen. I have script A require(scriptB), then have scriptB use the remote function to call a function in script A. There may be other uses but this is the one I know of

Yes I agree that this would be an acceptable use of it, however using custom signals like FastSignal takes out the worries of having objects in the workspace and puts it into a code dependent state which is prefered in any practice of codebase management.

The moment you use BindableEvents, you must have a dependent instance created within your workspace, which puts risk of one place not having it or it deleting itself for whatever reason. That does not happen with modular code Signals.

It is also a good idea to apply a specific structure to prevent such recursion except if absolutely necessary. Using/Creating a Module importer allows one to import the module later on if necessary, and prevents that recursion.

The only way I would use BindableEvents is through the Reset button callback.

I usually use BindableFunctions to get data that only the server can access and send it back to the client

In that case, you can just have both modules require a “middleman” module to literally connect their environments. A and B requires C, rather than A and B requiring each other. You could also use SharedTables, even though that’s meant to be used for parallel code. Both of these options should be more performant than using bindables to transfer data, which is susceptible to bandwidth bottlenecks, deferred events, and any other problems related to instancing.


You mean remotes. Bindables can’t transfer data between server and client.

1 Like

You’ve got it the wrong way around. Remotes only go one way, BindableFunctions send and receive (called “invoking”).

“The BindableFunction object allows for synchronous two-way communication between scripts on the same side of the client-server boundary”

Read it again carefully lol.

ON THE SAME SIDE, implying that it cannot cross it.

This would still produce issues should C module require loop back to A… Not to mention dependencies at the start of the module towards the recursed modules would produce many unpromised results.

The idea is that the middleman module is an empty “slave” table that doesn’t do anything on its own. It only read and write values to a table that is accessible by its masters. If it ever did have free will then it would fall under your solution of using a module importer :stuck_out_tongue:

It does say that but, you can use BindableFunctions like how I said earlier. I quite literally do it in one of my games.

-- Server
local function GetDifficulty()
    return "Hello World!"
end

ReplicatedStorage.GetDifficulty.OnServerInvoke = GetDifficulty
-- Client
local defaultSpeed = ReplicatedStorage:WaitForChild("GetDifficulty"):InvokeServer()
-- defaultSpeed would equal "Hello World!"

My brother in Christ, you are confusing bindables with remotes big time.

This is a method of a RemoteFunction, not a BindableFunction.
image

Well crap. Well I must apologise for misremembering what one is which! :sweat_smile:

3 Likes

I see what you mean now! In the grand scheme of a codebase, I feel as if this would be quite an uncommon occurence and practice… but indeed it would produce the results. This should only be used as a last result as well :laughing:

1 Like

It’s better to find out now than later. Breaking that habit way later would be hell :sweat_smile:

While I appreciate the debate and banter, no one has given a definitive answer. To clarify Bindable events and functions do not cross client server boundaries, that is remote events/functions . To communicate between scripts on the same side I have always used module scripts. I really want to know is there any situation where Bindable events / functions are a better solution or is using Bindables just an alternative? :slight_smile:

In my beliefs, Bindable Events are already good enough to communicate between servers and transfer between data and processing whatever values instead of client’s interference. If you’re a person that’s obsessed with separating scripts (like me), and often struggles with Modules or Libraries a lot (and I heavily struggle on understanding the concept of it too), you would use Bindable Events. Let’s say you want to transfer data of player coins from DataStore Script to script where it processes purchase and then initiate another event which confirms and returns the post-purchase value of coins. In my personal experiences, it’s more convenient when you rely on time-management and provides more real-time analysis compared to ModuleScripts. I’m sorry for the messy explanation, but I hope this gives you a great idea. :yum:

Don’t want to say this, but likely an alternative.