Will indexing things that don't need to be make my scripts less optimized?

Will indexing things that don’t need to be make my scripts less optimized and slower? such as something
local Head = Character:findFirstChild(“Head”)
in many multiple scripts.

1 Like

Yes. FindFirstChild is slow relative to directly accessing it with Character.Head, the difference is FindFirstChild won’t cause your scripts to error if it’s missing. The docs say that FindFirstChild takes 20% longer than . and takes 8x longer than just saving a reference to it. Avoid many calls to FindFirstChild when possible, especially in loops (and even more so in scripts connected to the renderstep).

1 Like

WaitForChild is typically the better alternative to FindFirstChild.

It really depends on what you’re trying to use :FindFirstChild() or :WaitForChild() on. If you’re working with server code and none of the objects were created from a client then replicated, you’re pretty safe to use . instead of :FindFirstChild() because you know the child of that object exists.

:WaitForChild(), for me at least, is mainly used on the client (especially when doing frontend programming >_>, very tedious) because you have to give the client time to have those Instances loaded in.

2 Likes

Thanks thats what I needed to know.