They actually run sequentially not in parallel also the order depends on which was conncted first That’s why each connection runs to completion before the next starts , if you really want true parallelism use the task library
The task library is not true parallelism. They are still just coroutines. Luau is a single-threaded language. Everything runs in serial. The events already run in their own coroutine threads, so spawning another within the connection is pointless.
If you want true parallelism, you need to use Actors, which run in separate Luau VMs, and allow you to “desynchronize” a block of code from the main thread.
There’s a difference between multiple threads and parallel threads. Multiple threads can run on one CPU core, while parallel threads run on different CPU cores.
Oversimplification warning!
Think about it like a group of friends working on a bunch of tasks. Each friend represents a CPU core. Now, there’s also a bucket full of tasks. Each task represents a possible thread.
Multithreading (having multiple “connections” running at the same time on one core) is like one friend choosing to juggle multiple tasks at once. That friend will work on one task until they’re done the task then move on to the next.
Parallel threading (having multiple “connections” running at the same time on multiple cores) is like multiple friends completing different tasks all at once.
Now let’s say we had 100 tasks and each task takes 1 second to complete. If we only make one friend do it, it will take 100 seconds.
However, if we split those tasks equally among the 4 friends, each friend only does 25 tasks so completing 100 tasks will only take 25 seconds.
In your case, your two connections are two threads running on the same CPU. You aren’t giving tasks to any other core. CPUs run billions of times per second which makes operations extremely fast and so it seems like it runs at the same time. In reality though, it’s running each connection one after the other.