Answered by
4 years ago Edited 4 years ago
Explanation
It is extremely useful because whenever you start a game or join one, some instances may not have loaded yet and WaitForChild
is really efficient. Let's suppose you have a large map in your game and it takes some time to load. You'll have to use WaitForChild
so that it ensures that the map is FULLY loaded.
Here are some examples. The script down below is for my game that ensures that things UI's and maps are loaded in my game.
1 | local map = game.ServerStorage:WaitForChild( "Map1" ) |
Things to know
WaitForChild is used when you want the script to wait for something to load before continuing the whole script.
WaitForChild is extremely important for variables and it is really efficient as well.
Let's say that If you store a map in ServerStorage or ReplicatedStorage, it may not have loaded when you start the gameWaitForChild
is going to be used. An example is down below!
1 | local fightingMap = game.ReplicatedStorage:WaitForChild("Map 1 ') |
3 | local sword = game.ReplicatedStorage:WaitForChild( "Sword" ) |
5 | local parts = game.ServerStorage:WaitForChild( "Parts" ) |
Please make sure to select this as your answer if this helped!