Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

What is RBXScriptSignal:ConnectParallel() and RBXScriptSignal:Once(), and how do you use them?

Asked by 1 year ago

I was just making a RemoteEvent, when I noticed that the Event has the functions :ConnectParallel() and :Once() and I wonder what they do. They don’t have a documentation in the wiki. I checked the DevForum and there are not much posts about them. I read the posts and I still don’t understand. So I’m asking in this website instead. Thank you!

1 answer

Log in to vote
2
Answered by
xXMadonXx 190
1 year ago
Edited 1 year ago

Because you did not understand the Forum, i am going to try and make this as descriptive as i can. It may cause that there is a lot of information you already know.

I am also referring to CPU Cores but with that mean threads. (To make it simpler)

:Once()

Basically :Connect() but it detaches itself automatically after the first call. Means: It runs the connected function once and then never again until you reconnect it.

ConnectParallel()

First you need to understand that a CPU Core can only do one thing at a time. Meaning: Your CPU can only run 1 script at a time. If we wanted to run multiple things at a time (to speed up certain processes), we can do either task.desynchronize() or :ConnectParallel() which basically uses more CPU cores.

To use the function 2 things must be true:

  1. The scripts must be parented under different Actor instances

  2. The thread within a script must be desynchronized either via task.desynchronize() or Signal::ConnectParallel

(If you know what task.desynchronize() is, then :ConnectParallel() is basically the same but more efficient than using :Connect() + task.desynchronize(). )

If you ever worked with coroutines, you know that multiple lines of code can run at the same time. Coroutine works on one core still though and is synchronized with all other tasks because of that (it runs the same speed with other tasks).

Now if you are running something unsynchronized, it runs on a different CPU Core and may be faster or slower depending on Workload. This introduces a bunch of Problems as you may need to yield Code to wait for everything to be there and not miss information.

Do not just Slap :ConnectParallel() everywhere, as it may either decrease performance or cause a lot of Errors. If used correctly though, it may speed up things significantly!

Basically think of it as a Team: One Person can do one task at a time with little errors. If you spread the Workload onto a Team, it is done faster but introduces more errors because people do not exactly know what to do exactly or how to do it. There is more communication needed.

I hope this helped a bit! If you do not understand it, stick to :Connect() and coroutines as it may introduce many complicated Errors or slow down code.

0
What do you mean by different actor instances? What are actors though? I never understood what actors are since they released. T3_MasterGamer 2189 — 1y
0
An actor is a container for code. Basically a script is an actor. It just means that the code needs to be from different scripts. xXMadonXx 190 — 1y
0
Okay thx! T3_MasterGamer 2189 — 1y
0
So basically :Once() disconnects itself after running the function, right? T3_MasterGamer 2189 — 1y
View all comments (3 more)
0
And :ConnectParallel() converts the listener into a coroutine, and task.synchronize stops the coroutine and converts the listener into :Connect(), right? T3_MasterGamer 2189 — 1y
0
If so, this will be helpful in making my own custom Signals using OOP! T3_MasterGamer 2189 — 1y
0
ConnectParallel starts the code on another CPU core, not in sync with the actual script. task.synchronize then makes that into a coroutine to have it running in sync with the script. xXMadonXx 190 — 1y
Ad

Answer this question