Common need: Find the humanoid of a character immediately when it becomes available after spawning.
Usual solution: WaitForChild.
humanoid = character:WaitForChild'Humanoid'
Why this is bad: Your code breaks if the humanoid isn’t named Humanoid, or if there’s another member of the character that happens to be named Humanoid. It’s ugly to make assumptions about name.
humanoid = character:WaitForChildOfClass'Humanoid'
July 31, 2017, 8:19pm
It’s worth mentioning that this should also have a timeout parameter like normal WaitForChild.
July 31, 2017, 8:22pm
Yeah. There should be equivalent “WaitForX” methods for all the new “FindFirstX” methods.
July 31, 2017, 8:27pm
WaitForChildWhichIsA makes sense to me, but I’m not sure about the Ancestor versions. I don’t see a good use case there.
July 31, 2017, 8:28pm
That’s fair. Would be a strange use-case to be sitting around waiting for a specific ancestor.
Yeah there have been times where I could use this (maybe quite a few lol) Support.
August 3, 2017, 4:25am
Makes sense, I think it’s good because other methods require more lines of code. This would make it more efficient.
August 3, 2017, 7:54am
I’m happy they finally added a timeout parameter. It only took 2 years and a lot of arguing
August 23, 2017, 1:04am
Not to mention
:WaitForAncestor() and of the like would be great too.
While I do support this API, when I read the title of the thread I immediately of the bigger brain meme.
FindFirstChildOfClass() exists, it would make sense to add
This would be useful, support!
November 12, 2017, 8:27pm
This would be a very useful tool for us developers.
(I tried to use it just now and realized it didn’t exist… )
November 12, 2017, 8:33pm
I guess I work here now…
I’ll put it in my backlog.
September 3, 2018, 1:49pm
I just really needed this and I’m disappointed that such an obvious feature wasnt added yet…
It’s also surprising considering :FindFirstChildOfClass is a thing, I was expecting the same in this case.
I think this really deserves to be added.
September 5, 2018, 10:54pm
We decided against adding this, I’ll explain why.
Here were some of the obvious use cases:
Waiting for PlayerScripts to replicate
Waiting for Humanoids to replicate
Waiting for PlayerGui to replicate
You can see a theme where scripts are trying to use objects before they’re replicated–there are no guarantees that critical things will exist by the time scripts run.
There’s two ways address that:
Make an engine-level feature to work around the lack of guarantees; add WaitForChildOfClass
Get to the root of the problem and add those guarantees
Better to patch the boat than waste time bailing water, so we’re opting for the latter. This means more predictability and fewer edge cases in the long term.
Short term, you only need a few lines of code:
local function WaitForChildOfClass(parent, class)
local child = parent:FindFirstChildOfClass(class)
while not child or child.ClassName ~= class do
child = parent.ChildAdded:Wait()
January 15, 2021, 4:10pm
In case anyone wants a version that works similar to the Roblox one with a single warning and an optional timeOut
local waitTime = 0
local warned = false
local obj = parent:FindFirstChildOfClass(className)
if obj then
waitTime = waitTime + wait()
if timeOut then
if waitTime > timeOut then return nil end
elseif not warned then
if waitTime > 5 then
warn("Infinite yield possible waiting on",parent:GetFullName() .. ":FindFirstChildOfClass(\"".. className .. "\")")
warned = true