Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

I read about FindFirstChild() and figured out it will make my performance worse, how can i fix?

Asked by 4 years ago

I read it from wiki, I really like FindFirstChild() and use it a lot. But i scared my performance will be bad. What should i do?Any good built-in functions/events i can use to replace FindFirstChild()?(except WaitForChild()) The source of my information: https://developer.roblox.com/en-us/api-reference/function/Instance/FindFirstChild "Performance Note

FindFirstChild takes about 20% longer than using dot operator, and almost 8 times longer than simply storing a reference to an object. Therefore, you should avoid calling FindFirstChild in performance dependent code, such as in tight loops or functions connected to RunService.Heartbeat/RunService.RenderStepped. Store the result in a variable, or consider using ChildAdded or WaitForChild to detect when a child of a given name becomes available."

0
FindFirstChild is mainly used when there is a risk that the specified reference object may be nil. In this case, the FindFirstChild will simply return nil and will not terminate the program upon error. Ziffixture 6913 — 4y
0
The WaitForChild method will yield the program until the referenced object becomes available; it will wait until the instance exists if it appears to have not found it. Ziffixture 6913 — 4y
0
This is why it is advised to be using WaitForChild as a program that is strictly dependent on requiring the referenced objects or declared allocations as if it accidentally tries to perform an action on a nil instance it will stop running and possibly cause issues down the road through collateral. Ziffixture 6913 — 4y

1 answer

Log in to vote
0
Answered by 4 years ago
Edited 4 years ago

There is no "fix" You just gotta use your head and use it as efficiently as possible if you want the best performance

e.g

-Only use it when theres a chance the part doesnt exist when the code run

-Dont use it inside a loop or something like that

Ad

Answer this question