Does using ":FindFirstChild()" too much cause lag?

I’m trying to optimize my code and wondering if using “:FindFirstChild()” too much causes lag.

it is slower if you do not store the references, reuse the result as a variable like so.

local mypart = script.Parent:FindFirstChild("mypart")

mypart.BrickColor = "red"
mypart.Transparency = 0.5

BUT even this is a very very very small optimization maybe a nanosecond gain. Try to reduce stuff in this order and you will get much more out of your scripts.

  1. Yeilding functions (wait, WaitForChild, http requests, remote/bindable functions)
  2. loops inside of loops
  3. raycasts
2 Likes

It does not cause lag, however it is approx. 20% slower than using the dot operator.
You should know when to use it.

The correct way to use FindFirstChild would be:

local mypart = script.Parent:FindFirstChild("mypart")
if (mypart) then
    -- // Modify the part's properties here.
else
    -- // Part does not exist.
end
2 Likes

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.