Let’s say this player have bad internet connection and like this player’s ping is like 1k+
and it takes like 5+ seconds to load in the proper objects that your script needs
Of course if it doesn’t load in fast enough without the asset or the object it needs it will yield the whole script…
QUESTION IS
is it a good practice to always have a timeOut Parameter when using :WaitForChild()?
How would you handle Player having bad internet connections
How can I prevent important scripts from breaking due to missing assets in high-latency situations?
No. It’s a case by case basis, though I stead of an infinite yield with wait for child depending on the script you might want to change your structure (like answer 3)
generally bad Internet connections aren’t that bad. 5 seconds is a very long time and that’s how long it waits before warning you by default. Though it probably continues waiting.
make it so that anything missing assets can just skip parts that require it as they run and come back later and fix it when the thing exists. Doing this can be tricky. But like if you are running in a loop you could just check if instance:FindFirstChild(name) and handle that instance in there instead of yielding for it.
As @tlr22 said, you can try something like this (not really code, but you get the idea).
WaitForChild(item)
do code that allows other items to load in
if not item then
try waitforchild again, possibly with a longer wait time
end
I would recommend using a timeout in sensitive areas where infinitely yielding would be bad for example, some type of server sided system, but other than that you don’t need a timeout. In most cases you don’t actually need WaitForChild either. It only applies to the client in workspace when streaming enabled is on, and instances that are created at runtime (you don’t need to use WaitForChild on anything in ReplicatedStorage, SoundService, etc).