How to pass functions between scripts using a bindableevent

currently something im having on my list of things to do is making voting generalized to a script instead of a fragmented mess (which is the current system)
but i don’t want things centralized on the script and like i said in the title, pass functions around, anyway to do this?

You can’t pass functions through Roblox bindable events. You can, however, pass functions through custom Luau signals (which are just an array of callback functions, and :Fire calls each of those functions with the provided arguments). I recommend this one.

What exactly are you trying to do with your voting system? By firing the bindable when something happens and having other systems connect to it (like how you would normally use a bindable event), you are separating the voting logic from the rest of the game logic. Personally, I’ve never had to pass a function through a signal.

i did notice that on the documentation, nothing is listed as “USE STRINGS ONLY!!!” and instead just tuple, which i must assume means free rein over types and functions are types so… (although i have to implement the system to see if it works😔)

actually would loadstring work? (the main concern about that one is client getting access to it which won’t happen since this bindable is a server goober)

Probably stay away from loadstring. I’m not sure why you would need to use that when you can just pass the function by reference using a signal.

If you really want to keep using a bindable, why not put the function in some module and send the function’s index in that? Then, listeners can easily access the function from the module. I don’t suggest doing this, though. Use a signal library.

1 Like

You can put your functions in a table and then pass that table into a BindableEvent via :Fire() that works for me.

i’m just going to embed the functions into the script and deal with a bunch of variables

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.