When writing a local script in “ScreenGui” which is in “StarterGui”, I want to make sure that all the right parts have replicated to the client and I can reference them.
game:IsLoaded()
Not suitable because the game is considered loaded even if not all “PlayerGui” objects have been replicated to the client
example
Here you can see that the loading of the other Gui has not yet finished, but the game is considered loaded
And writing :WaitForChild(“”)
for ALL objects is obviously not the best solution
I started looking into how objects are replicated to the client, and I noticed a pattern:
Any local script under a shared “ScreenGui” will only run after that “ScreenGui” is fully replicated to the client.
The code on scripts “0”, “1”, “2” is the same (green line).
The output, which object is replicated, is done by “LocalScript” (orange line).
With the red lines, I showed that the “0” script was loaded at the beginning. And at the end the “2” and “1” scripts were replicated.
And only after the last object (in this case “1”) was replicated in ScreenGui called “adin”, all 3 local scripts started. First “0”, then “2”, then “1”.
And after that, the replication of the next “ScreenGui” started
I don’t understand if it was intended that way, or if it happened by accident
And it comes out: :WaitForChild("")
is not needed? If you only refer to objects under the same ScreenGui.
Bottom line: I don’t have to worry about any “ScreenGui” descendant not being replicated, since the local script won’t run until all “ScreenGui” descendants are fully replicated?
If this is the case, it is strange that the documentation does not mention it, because it is very important