This post is made out of curiosity and is not blocking.
It’s widely perceived that script execution order on Roblox is non-deterministic, and discussions seem to end at that.
You can make your own code’s execution order deterministic through micro managing the modules, but in the context of the following, it does not apply and is purely script based.
Based on what we experienced below, it seems that Roblox does in some way pre-determine script execution order, perhaps even on a luau thread level, but the big question I’m seeking an answer to is what Roblox is really doing under the hood that could result in these per-place side effects.
In short…
Roughly two months back, we transferred the testing version of our game over from a player to a group for the features it offers, using the experience ownership transfer tool, in preparation for transferring the prod version later.
After doing so and playtesting, a bunch of game-breaking bugs that we never experienced before started popping up.
The code was nearly identical to the prod version that was still up and running, not experiencing these issues.
From what I can remember, the bugs were all caused by individual race conditions, most of which were easy to fix within a few minutes, but others proving to be a headache for a good half an hour.
Why and how?
The fact that this happened at all is a good indicator that a complete lack of managed startup sequences for the game’s logic is a potential recipe for headaches later down the line, besides being terrible for your game’s startup performance (…and sanity having to work with it ).
Question is… why did the threads seemingly execute in completely different orders after transfering the game?
If it was truly non-deterministic from the start, we would’ve encountered these bugs before.
Instead, we encountered them all in one big wave right after transfering.
What is Roblox doing under the hood that could potentially be a player in this?
First I will note a few things. It’s not necessarily non deterministic. It’s generally just no ordering guarantees. (though non determinism can fit in here as well). Often things are strictly undefined by implementations not because they don’t currently have an order or a way to load, but because they are free to change it at any time and the ordering may not be consistent. So it’s not that there won’t be a load order, it’s that roblox isn’t promising you one to rely on.
As for what roblox may be doing? Not sure. Game engines are complex and there is a lot of reasons this could be happening. As for a way this could be happening, I can describe why this would probably happen in my game engine. Whether it’s the same or similar reasons in roblox is not something I know.
Why my game engine would probably do this
In my engine when you make a new script or pull one into a new project the first thing it does is assign an ID. I use this ID internally to handle asset management things, like getting the actual script from file to load into the engine to run. The actual process this goes through to load and stuff is too much to really go into here, but suffice it to say, that as of rn it just so happens that the very first script execution phase will be in the order the scripts loaded into the dispatcher originally, which also just so happens to be the same order if their asset IDs are sorted (because they are sorted in the manifest this finds the asset from. Technically it actually doesn’t load in direct asset order but it simplifies things to pretend it does). Because of this, for that scene, you basically will always get the same load order for the scripts. Now though if we make a new project in my engine, and start bringing in the scripts, it will be assigning those new IDs which will effectively change the loading order. And that’s why my engine will likely have the same issue. I’ll note though that the way my engine loads these things is not a promise, it’s just how it is rn. I may change it at any point which WILL alter in which order the scripts run. This means it is unsafe to rely on that order in my engine even though it does happen to do that rn. (I’ll note that due to a couple other things, you may actually get different orders between tests, but that’s a multithread reason, not a loading reason)
This is just one example though that could cause this. There are very many reasons why this could happen in other engines like Roblox. Overall though, it’s not uncommon for something like a game engine to technically load scripts in the same order even if they don’t promise that order to you. It’s more just about them having a consistent understanding you can have about ordering assurances (or lack thereof) so you can know what the engine will handle, and what is your responsibility to manage. Keeping these expectations consistent is what matters so you can know what you need to do to keep your code working, even if they change some things under the hood.
This makes a lot of sense as a potential reason why.
I’ve never made my own engine before and only utilized existing ones like Godot, so I wouldn’t be able to reach a candidate like this myself. (^^ゞ
Also, when it comes to Rojo projects on Roblox, it makes sense that they (most of them) don’t experience this same issue because by design Rojo encourages a single-script architecture, and the modules are loaded in the same order as they are defined in the script.
This likely is why despite the project files being rebuilt across developer systems & places, you don’t see them mentioning this issue (at least I haven’t!).
Perhaps a bit off-topic to ask in the Scripting Support section, but what lead you to writing your own game engine, and what are you (vaguely) aiming to create using it?