:WaitForChild() question

Hi, I’ve been wondering quite a while about this question about the :WaitForChild(). Basically a local sided script always needs this function to wait for anything to load in as the client needs to download it first. But my question is, when you’ve put a StringValue in the ReplicatedStorage (in studio, not in-game) for example, does a server sided script really need this function when using ReplicatedStorage.StringValue works just fine? I’m not sure if this is a dumb question, but I thought it might be less script work or even memory to not use this function everytime in a server sided script when the instance was added in the studio before the game even started.

In this API Reference it only states that it’s very important to use them in client scripts.
In servers scripts I guess it can be used in cases where the object you’re looking for might not be loaded at that moment. For example a players character and it’s apperance.

Other thing might be when having content streaming enabled.
In that case WaitForChild is very important otherwise the game would break if you don’t have any of them in your client scripts.

I doubt WaitForChild has any effect on memory. Even if there is it should be very minimal and not noticeable no matter how many you use.

I don’t know if I’m fully correct since I’m just going off of experience and documentation I’ve read.

1 Like

While this is accurate, this function is the least efficient of the dot operator, FindFirstChild, and WaitForChild. According to documentation:

This (WaitForChild) function is less efficient than Instance:FindFirstChild or the dot operator. Therefore, it should only be used when the developer is not sure if the object has replicated to the client. Generally this is only the first time the object is accessed.

We know FindFirstChild is slower than dot notation as well according to the docs:

FindFirstChild takes about 20% longer than using dot operator, and almost 8 times longer than simply storing a reference to an object.

It also notes that you should use WaitForChild and store it in a variable instead of repeatedly using FindFirstChild in a loop, but you should only do it once. Regardless using dot notation is always the fastest if you’re not going to cache the instance in a variable.

2 Likes

Every Instance in the explorer wouldn’t require you to use WaitForChild (with the exception of scripts in ReplicatedFirst and CoreScripts, as they run first) on the server-side. The only times you would use it on the server is if you’re instancing new Instances, or cloning objects. In which case, you would need to use WaitForChild because the Instances take time to load and cannot be indexed until it is.

So yes, that statement, “ReplicatedStorage.StringValue” works fine on the server if it already exists.

1 Like