Introduction
I will discuss about replication behavior of instances and what you can expect.
Everything described in this thread tested by me, so this information should be correct, this described behavior is 100% safe, so don’t worry.
Feel free to correct me or add something.
Contribution
I made this thread because it’s really important theme, but it’s really hard to find anything about it as detailed as I wanted it to be. Dear reader, I need your help to make this thread easy to find!
If someone will need info about replication behavior - just send link to this thread.
Static / Dynamic Instances
There’s 2 types of instances - static and dynamic.
Don’t worry It’s not something hard.
-
Static instances - instances that replicates before game.Loaded signal, this is everything inside ReplicatedStorage / StarterGui / PlayerScripts.
Those instances already pre-created in your data-tree by you (data explorer).
Server scripts / Local Scripts are executed after game.Loaded (There’s no game.Loaded on server, but for sake of abstraction think it exists). Not all Local scripts however, if they inside ReplicatedFirst - they executed before game.Loaded.
So, after game.Loaded - every static instance is replicated. -
Dynamic Instances - instances that replicated at runtime, no guarantees that they will be available or that their descendants will be available.
Replication Behavior
We know that static instances are our friends - we can access them freely without fear from scripts, but what about dynamic instances? That’s great question, after some tests I figured this out.
You literally haven’t any guarantees, if dynamic instance was replicated - it might have children and children of children, but again - it depends on player’s network quality.
So, use WaitForChild to access children of dynamic instance.
It’s same replication behavior for every instance in game, static instances “bypass” this behavior only because of game.Loaded, but if we run script before this event - everything is dynamic instances. Replication is not performed layer by layer, it’s random - don’t rely on order. For example if you have 10 children and 1 children inside each - it’s not guaranteed that at first will be replicated those 10 children without each.
Replication Order
Replication order is always stable.
For example if we replicated large model and after that small model - first will be replicated large model, and after that small model. However, remember that children are not guaranteed to be replicated with this model (we discussed this in Replication Behavior).
Streaming Enabled
Replication behavior is the same, but every BasePart inside workspace is dynamic instance.
Without streaming enabled - every BasePart inside workspace is static instance.
Don’t expect that part will be replicated with folder as child for example, it will in 99% cases with good ethernet, but that’s not guaranteed!
StarterGui
That’s not something different from what I described above, but maybe useful for your understanding.
Every ScreenGui is cloned from StarterGui to PlayerGui on Character spawn, if you don’t know about those replication rules above you might think “Every ScreenGui is dynamic instance, I can’t access it’s children safe!”, but that’s wrong! Local scripts that are not inside ReplicatedFirst are executed after game.Loaded, that means that StarterGui children were already replicated, so they are static instances, they will be cloned to PlayerGui on Character spawn (clone is synchronous)!
So, now we can just wait for ScreenGui and all its children will be available.