YouTube2Text

Bindable Events & Bindable Functions - Roblox Advanced Scripting #16 — Transcript

by BrawlDev · 4,473 words · 242 segments · language en · Watch on YouTube

Full transcript

  1. 0:00there is a button here and I sure am tempted to  press it all right let's see what happens whoa
  2. 0:05okay so it looks like the sky changed to nighttime  the base Plate's color changed to Pink and I think
  3. 0:12the material changed it to uh neon as well hold  on I got to see what's happening here with the
  4. 0:17script okay this is a bindable event it looks like  and it's being fired but where is this being fired
  5. 0:22to I think it's probably in script 2 yeah okay so  it's being printed here inside of script 2 when
  6. 0:27it's catching the event call but what's weird is  that it's only doing one of the things that we saw
  7. 0:32in the workspace which is change the the lighting  so where where else is this being called so maybe
  8. 0:38it's in script oh oh I see I see so this is where  we're doing the second thing and I imagine script
  9. 0:444 is when we're doing the other thing yeah okay  so what's interesting is that it's making this
  10. 0:49fire function one time but then it's being uh  caught in all of these three different scripts
  11. 0:54that are doing different things and keep in mind  these are scripts these are not local scripts to
  12. 0:59scripts or script scripts to local scripts these  are just scripts communicating among all these
  13. 1:03other different scripts to do different things  okay I think I I understand this model pretty
  14. 1:08well I think we should probably put this into  more practical use all right let's think about
  15. 1:12this for a minute so if you remember remote  events and remote functions I made a video on
  16. 1:17this uh earlier in this guide so if you haven't  seen that I recommend you watching that first
  17. 1:22before watching this one because what we're going  to be talking about today kind of branches off
  18. 1:27from what we're learning about the server and  client communication going back to that sort
  19. 1:31of stuff so this is an expansion on that um  but anyways if we remember what remote events
  20. 1:37did this basically acts as one-way communication  across the server and client model that allows
  21. 1:44both sides of the game to communicate with each  other and because of this we're able to do all
  22. 1:49sorts of things where if we needed the server to  do something based on the client or the player
  23. 1:53in this case then we would use a remote event to  make that communication happen and if let's say we
  24. 1:59wanted to to make that communication happen but  then retrieve information back known as two-way
  25. 2:04communication we would use remote functions so one  important thing to know about with remote events
  26. 2:10and remote functions is that they both allow us  to communicate from the server to the client or
  27. 2:16the client to the server and that is something we  need to recall and remember from during uh during
  28. 2:22that video that I talked about these two things  because knowing this this is how we're going to
  29. 2:28implement what's now known as bindable events and  bindable functions which is what I'm going to be
  30. 2:34showing you how to do in this video now that we  understand it let me give you a brief rundown of
  31. 2:38what bindable events are so from what we just  said with remote functions and remote events
  32. 2:45they act as communication between the server  and the client but think of bindable events
  33. 2:50and functions as if they were one way in two-way  Communications between the server and the server
  34. 2:58or the client and the the client so there's no  stepping into from one side of the game to the
  35. 3:02other side of the game it's more like if you had  a script communicate with another script or if you
  36. 3:08had a local script communicate with another local  script that is basically what we would be doing
  37. 3:13with these bindable events and bindable functions  so if let's say you had one of these scripts like
  38. 3:18in my previous example and so with this one fire  call we would catch that in multiple different
  39. 3:24scripts to then do multiple different things  at once if let's say we had multiple scripts
  40. 3:29that needed to catch the same event and make it  do whatever it is that we needed to then that is
  41. 3:35pretty much how we would use communication between  the server among multiple server scripts and so
  42. 3:41that is basically what we would do here so with  this in mind I'm going to show you an example of
  43. 3:44how we would use these bindable events inside of  our game apart from the one I just showed you so
  44. 3:49in order to start we first need to add in our  bindable event so much like our remote events
  45. 3:54we need a place to put this inside of the game and  ideally the best place would be replicated storage
  46. 4:00so let's hit the plus sign next to replicated  storage and let's add in a bindable event so this
  47. 4:05is pretty much what it's going to look like and  we can rename this bindable event to whatever we
  48. 4:09want to just say bindable event and then what we  can do now is create a script in let's say server
  49. 4:16script service so let's hit the plus sign include  a script in here and let's make reference to our
  50. 4:21bindable event by saying local bindable event  equals game. replicated storage colon wait for
  51. 4:30child bindable event so now that we have reference  to our bindable event let's make this first script
  52. 4:37the script that we're going to use to fire this  bindable event so the way we're going to do this
  53. 4:42is by simply saying bindable event colon fire  open and close parenthesis so this is basically
  54. 4:50how we're going to uh fire this bindable event so  that we can catch it in a different script to make
  55. 4:55it do what we needed to uh to be able to have this  server to server communication cuz that's what we
  56. 5:01that's what we're going to do um with this example  is to communicate from one server and catch this
  57. 5:07fire call in another server script in order to  do what we wanted to do with this communication
  58. 5:13that's happening so if you really think about this  if let's say this was a remote event this would be
  59. 5:18equivalent to fire server and fire client so this  fire event is so this fire function is basically
  60. 5:26the same thing as fire server and fire client  but this time we know that we're communicating
  61. 5:32from one side of the game so we don't need to  add in this fire server or fire client um name
  62. 5:39to it we can simply just say fire no matter  no matter where we are whether we're in the
  63. 5:44server or whether we're in the client using these  bindable events so that's an important so that's
  64. 5:49an important correlation to uh note there but now  that we have the fire function let's catch it in a
  65. 5:54different script so on the right side let's rename  this script to uh bindable and then let's insert a
  66. 6:01new script here and let's call this bindable 2 all  right and so now let's copy our reference to the
  67. 6:08bindable event from the previous script and put  it inside of here so let's drop two lines so now
  68. 6:12what we're going to do is catch this fire event uh  is catch this fire function call into an event and
  69. 6:19the way this is going to be structured and this  is pretty important bindable event is an instance
  70. 6:23it's not an event itself so the way we're going  to get the event is by simply saying bindable
  71. 6:29event do event so this right here is the actual  event that we're trying to uh connect the fire
  72. 6:36function call to not the bindable event instance  so that's important to know about then what we're
  73. 6:41going to do is say colon connect open parenthesis  function open close parentheses enter and so now
  74. 6:49what we can do is just do something random here  by saying uh bindable has been fired and there
  75. 6:58we go that is basically the very basic uh setup  for using bindable events so let's go into the
  76. 7:04game hit test and hit play so that we can see in  the output that we're going to be printing out
  77. 7:09uh yeah bindable has been fired so as soon as we  join into the game then the the output has printed
  78. 7:15out bindable has been fired because we were able  to take the bindable event and fire this Comm and
  79. 7:20fire this function so that we can pass it into  the second script to then do what we needed to
  80. 7:26do so we were able to effectively communicate  between between one server to another server so
  81. 7:32this isn't some communication that we're going  from the server to the client or the client to
  82. 7:35the server but once again this is either from  the server script to another server script or
  83. 7:40a client script to another client script so that  is basically the structure of how these things
  84. 7:45work another thing we can do is add multiple  arguments to this bindable event now here's the
  85. 7:50interesting thing about bindable events that make  it stand out from uh remote functions and remote
  86. 7:55events so you know how when we're specifying fire  server and fire client and we use on server event
  87. 8:01and on server uh and on client event to give  us automatic arguments when we pass in these
  88. 8:07things so what I'm talking about here is when  we're saying on server event for instance and
  89. 8:12we have the open close parenthesis with uh player  being the first argument by default we have things
  90. 8:19like this to worry about but the interesting  thing about bindable events is that we don't
  91. 8:23have to worry about automatic arguments being  thrown into here because we know exactly what
  92. 8:28we're trying to fire we know exactly what we're  trying to catch when we're communicating between
  93. 8:33the server and the server or the client and the  client so if let's say we had two parameters here
  94. 8:37with num one and num two then our arguments here  is also just going to be num one and num two so
  95. 8:44whatever number one and number two is going to  be so let's say 5 and 10 we know exactly what
  96. 8:48we're going to be passing and what we're going  to be catching with this event we don't have to
  97. 8:52worry about any implicit arguments that are going  to automatically be passed in um just randomly so
  98. 8:58then what we we can do is we can pretty much  say print num one let's say num one plus num
  99. 9:04two that's going to be 15 so if you go into the  game now and hit play then we should see in the
  100. 9:09output that our result should be 15 after we print  bindable has been fired and there you go that is
  101. 9:14basically working as intended too so that is how  you add arguments to uh these bindable events and
  102. 9:20also bindable functions but we'll get to that in  a little bit all right so now I want to show you
  103. 9:23something interesting that you may or may not  have seen before and that is handling multiple
  104. 9:28ambiguous arguments you might ask what that means  okay so I want you to put things into perspective
  105. 9:34so up until this point when we've been writing  these event functions they have specific number of
  106. 9:40par they have a specific number of parameters and  because we have a specific number of parameters we
  107. 9:45have a specific number of arguments so num one and  num two so we have five and 10 when we're actually
  108. 9:51calling when we're actually firing this event so  there's actually a really interesting concept that
  109. 9:57we can apply to accept as many arguments as we  want if let's say we had this script bindable
  110. 10:042 that catches this bindable event and let's say  we had bindable 3 as a whole new different script
  111. 10:10that can accept as many arguments as we want to  uh to then do what we needed to do specifically
  112. 10:16for these scripts knowing that we have passed in  M these multiple different arguments put together
  113. 10:22this is what's called Ellipsis according to Roblox  and this is essentially saying that if we pass in
  114. 10:28as many arguments as we want like let's say we  have 4 2 and then n these are five arguments
  115. 10:33but this only takes in two parameters the way we  can do this is we can delete these parameters and
  116. 10:39simply type in dot dot dot and this is basically  saying that we can pass in as many arguments as
  117. 10:46we want uh and it will not break the script uh  but here's one important thing to note about with
  118. 10:52Ellipsis is that according to Roblox it's not  fully supportive with Ellipsis arguments so we
  119. 10:58have to do some sort of like hacky alternative to  this to be able to make this work for us so this
  120. 11:04is how it's going to work we need to put these  arguments inside of a table so the way this is
  121. 11:08going to work is let's delete this print statement  right here and let's make a table let's say local
  122. 11:13arguments equals open and close hard brackets  and then inside of here we're going to put dot
  123. 11:19dot dot and this is basically going to show us  all of the arguments put inside of this table so
  124. 11:25if we literally wrap this in a for Loop so by  saying four I comma V in pairs open and close
  125. 11:32parentheses arguments do print V if we go into the  game and hit and hit play what we should see in
  126. 11:41the output is all of the arguments inside of the  output in its own individual line so as you can
  127. 11:47see we have 5 10 4 2 and 9 those are the exact  arguments that were placed inside of here with
  128. 11:54this uh fire function call so we were basically  able to take it over here with this Ellipsis uh
  129. 11:59syntax and we're able to put this inside of a  table uh to then Loop through this table and
  130. 12:04check out all of the arguments that we have here  this is how you can take in an infinite number of
  131. 12:09arguments and take whatever arguments you need  inside of here to uh whatever you you need the
  132. 12:15script to do uh later on so now let me show you  what else we can do with this Ellipsis argument
  133. 12:20uh with handling all these multiple arguments if  you remember how indexing works we can basically
  134. 12:25tell which argument goes in which spot in this  table that we now put as arguments so what we
  135. 12:31can probably say here is do a check by saying  if arguments in hard brackets one so this is the
  136. 12:37first argument inside of the argument table so if  this is equal to five then what we're going to do
  137. 12:42is say um the first argument is five so that is  basically how we're going to tell that if this
  138. 12:50first argument is indeed the number five then  we're going to print whatever is down here so
  139. 12:55this is a little conditional we can do to check  if the arguments are valid valid so what we can
  140. 13:00do is we can join into the game okay so it seems  like it's firing it a bit too fast so I'm going
  141. 13:04to add in a task. weight here for 1 second so now  we should be able to see the result happen uh when
  142. 13:09we join into the game all right and there we go  so it says bindable has been fired and also the
  143. 13:14first argument is five indeed because we passed  all these arguments into a table and now we're
  144. 13:19able to tell which argument is which and so this  is very important for argument checking if let's
  145. 13:23say we're passing multiple different arguments  at once and catching them all inside of these
  146. 13:28different inside of these different scripts so now  that we've dealt with bindable events I'm going to
  147. 13:33show you how to use bindable functions which I  guess we can call this the the last of the big
  148. 13:38four which are remote events remote functions  bindable events and bindable functions so if
  149. 13:45you were to imagine bindable functions they are  pretty similar to remote functions except in this
  150. 13:50case it's a two-way communication from server  to the server or client to the client it's not
  151. 13:56two-way communication from server to the client  to the server and then client to the server to
  152. 14:01the client so you kind of get the idea there it's  structured in a way how it's like bindable events
  153. 14:07but you take the function part of remote functions  except it's now two-way communication among one
  154. 14:13side of the game so for instance I'm going to show  you an example of connecting from one script to
  155. 14:19another script and then back to the first script  using a bindable function so I'm going to show
  156. 14:24you how to do this so on the right side let's go  to replicated storage and let's add in a bindable
  157. 14:31function and this is basically what it's going  to look like so we're going to call this bindable
  158. 14:36function and now what we're going to do is go into  our first bindable script and we're going to make
  159. 14:42reference to our bindable function so we're  going to say local bindable function equals
  160. 14:48game. replicated storage colon wait for Child open  and close parenthesis bindable function so now we
  161. 14:56have our bindable function uh we're going going to  copy this reference and paste it into our bindable
  162. 15:012 script as well uh so now let's go back to our  first bindable script okay so now that we have
  163. 15:07reference to our bindable function how does this  work when we're actually going to communicate to
  164. 15:13the second server and then go back to the first  one so this pretty much Works similar to how uh
  165. 15:19remote functions work and how if we wanted to fire  a function and then retrieve information back from
  166. 15:25the second way communication uh we would basically  put this inside of a local variable so we can do
  167. 15:31the same thing here by saying local let's just  say result equals and then what we're going to
  168. 15:36do is we're going to say bindable function  colon invoke open and close parenthesis and
  169. 15:42much like the fire uh bindable event uh function  we just simply say fire we chop off the server
  170. 15:49and client related part and we simply just say  fire and we simply just say invoke this is all
  171. 15:55we need to say if we're either going from server  to server to server server or client to client to
  172. 16:00client so that's basically what we're going to do  here so this is going to invoke uh our catch over
  173. 16:06here inside of our second bindable script so down  here what we're going to do is we're going to say
  174. 16:10bindable function.on invoke so it's just going to  be on invoke not on on server invoke or on client
  175. 16:18invoke we could just chop those parts off what  we're going to say now is equals function open
  176. 16:24close parentheses enter Because as you know this  is how the syntax works if we're doing on invoke
  177. 16:28on server invoke or on client invoke or anything  like that um so then what we can do is just simply
  178. 16:33return a value of whatever the heck it doesn't  really matter we'll just say return uh success
  179. 16:40that's what we're going to say here so then we're  going to go back to our bindable script and let's
  180. 16:45print out our result with respect to our invoke  call okay and that's basically the syntax here so
  181. 16:50it's very similar to using remote functions except  in this case we're communicating from one server
  182. 16:56to another server and then back to another server  and not going from this transition from uh and not
  183. 17:01going from this hop from server to client when  we're doing it so it's basically the same thing
  184. 17:05so now we can go into the game and see this for  ourselves so if we hit run or if we so if we hit
  185. 17:11play then we should see that in the argument that  in the output it says that it printed success just
  186. 17:17like it expected because we got our bindable  function we called invoke and then we went to
  187. 17:22our second script and then we basically said on  invoke we wanted to return success if that was the
  188. 17:27case and then we were able to print our result  successfully so if let's say we were passing
  189. 17:32in arguments in this case uh rather than just  having it be a blank um invoke call we can pass
  190. 17:38an arguments by saying I don't know two numbers  two and four this time so now if we go into our
  191. 17:44bindable 2 script we can pass these two in as  different parameters by saying num one and num
  192. 17:50two and so what we could probably do in this case  is make this an Adder by basically adding these
  193. 17:54two numbers together so we can just return num one  plus num two so this adds the two numbers together
  194. 18:01and returns it as a result so now we can basically  go into the game and see this change for ourselves
  195. 18:06as well this is like another thing we can do  with uh this bindable event all right and so in
  196. 18:11the output we basically printed out six because  2 + 4 is indeed six when we passed in these two
  197. 18:16numbers brought it into bindable two uh it caught  it over here and then it returned the addition of
  198. 18:22these two numbers back into here and then we  printed it as the result so that is basically
  199. 18:27the so that basically how you use bindable  functions and passing in arguments into here
  200. 18:33so we can return it back if we need the result  so very similar to bindable functions except
  201. 18:38it's communicating from one part of the game now  you might ask what's the difference between these
  202. 18:43binda bles versus module scripts so let's say  I was back into the game and I created a module
  203. 18:50script inside of here and replicated storage  so module script and let's say with function
  204. 18:57module. my function open close parentheses enter  and then just like do something random so you
  205. 19:02might ask like if we had this instead of using a  bindable event it basically does the same thing
  206. 19:09because if we're firing this function to then  do something different we can effectively do
  207. 19:13stuff in a different script if we decide to call  a a customized event but in a module script it's
  208. 19:19kind of the same thing if we had a script that  let's say required this module and we basically
  209. 19:24just said module. function uh it would it would do  something a different script and not inside of the
  210. 19:30same script so there is a distinction between the  two that a module script cannot do that a bindable
  211. 19:36uh event can or a bindable function in this case  a bindable event a bindable event can catch one
  212. 19:44fire event for multiple different scripts but  a module script you can only call this one time
  213. 19:51in a specific module that's basically used more  for code reusability and less to do with script
  214. 19:57but script to script communication because  when it comes to that specifically bindable
  215. 20:03events are a lot more powerful because you can  use multiple scripts that catch the same fire
  216. 20:08call uh in comparison to a module script that you  can only just call once uh inside of a specific
  217. 20:14command and then it would just do what it needs  to do inside of here so that is an important
  218. 20:18distinction between using module scripts versus  bindable events that I think you should take into
  219. 20:22consideration when choosing which one to use  inside of your Roblox game so in summary the
  220. 20:28findables allow us to communicate from one part  of the game within different scripts of that same
  221. 20:34part of that same side of the game rather than  before when we used to use remote events and
  222. 20:40remote functions that allowed us to go from the  server to the client and then back to the server
  223. 20:46uh or just simply one-way communication of the  server to the client or client to the server so
  224. 20:50that is basically the idea of what we used remote  events and remote functions before in the past but
  225. 20:56now what we can do is do completely different  with bindable events and bindable functions
  226. 21:01that basically allow us to do one-way and two-way  communication in the same side of the server so if
  227. 21:08we were to let's say communicate from one server  to then another server then that's how we would
  228. 21:13use bindable events or if we wanted to do from one  server to another server and then back to the same
  229. 21:19server then we would do bindable events yet again  then we would do bindable functions in this case
  230. 21:24for two-way communication so I want you to just  take note of this and practice as much as you can
  231. 21:31just applying these four different uh instances of  of the server and client or one side of the game
  232. 21:40communication because when you when you actually  do understand the difference between all four of
  233. 21:46these and you can successfully use them in your  Roblox games that's when you know that you have
  234. 21:51understood this concept very well and these are  pretty important to use because technically you
  235. 21:57can go through without without using these in your  Roblox game especially the bindable events and
  236. 22:01bindable functions but they can definitely help  you out so much in the long run so I expect you
  237. 22:06to understand how these work and how you can apply  them because this because these will definitely
  238. 22:11save you a lot in the long run but with that  being said once again if you're still confused
  239. 22:15about this concept and you don't really understand  so much about the server and client model then I
  240. 22:19encourage you to watch my remote events video that  I go into great detail about that basically talks
  241. 22:25about stuff that we talked about here but in a  more simpler detail so go ahead and watch that if
  242. 22:30you haven't already I hope you enjoyed this video  and I will see you in the next episode take care

About this transcript

This page contains the full transcript of Bindable Events & Bindable Functions - Roblox Advanced Scripting #16 by BrawlDev, generated from the public captions YouTube serves with the video. The transcript has 4,473 words across 242 segments, with the original timestamps preserved so you can click any line to jump to that moment in the embedded player.

What you can do with it

Use the transcript to take notes, quote the speaker, build a study guide, generate a summary with ChatGPT or Claude via the YouTube Summary tool, or export it as a timed subtitle file with YouTube to SRT. You can also re-open it in the transcriber to choose a caption track available on the video.

Free YouTube transcript tool

YouTube2Text is a free YouTube transcript generator — no signup, no daily limit. Paste any YouTube link and get the full transcript instantly, with timestamps, click-to-jump, caption language selection, AI prompts for ChatGPT, Claude, and Gemini, and exports to TXT, SRT, VTT, or Markdown.