WaitForChild can't find existing instance

Alright, so I’m waiting for a tool to load in on a player’s backpack from a LocalScript
local tool = game:GetService("Players").LocalPlayer.Backpack:WaitForChild("Tool") however this gives me the infinite yield warning when I playtest it.

What’s weird is that if I do local tool game:GetService("Players").LocalPlayer.Backpack:WaitForChild("Tool", 5) local tool = local tool = game:GetService("Players").LocalPlayer.Backpack.Tool then it does find the tool… so this means that within the time that WaitForChild was looking, the tool did appear. So then, why didn’t it return the tool with the first time? Any possible reasons?

Sooo
I think I encountered this thing some time ago too.
I think the tool might load some scripts or smth and I think WaitForChild just does that infinite yield forever. This could be a bug too yk?

WaitForChild is an event, it’s basically a modified version of child added except it’s checking if the child added has the name passed to it and just yields the thread without spawning a new one.
Using find first child or direct access using . will return the instance found or nil.

So if the tool was already there, then the event won’t fire.

You can merge the two methods if you are unsure when or if something will load.

local tool = player.Backpack:FindFirstChild("myTool") or player.Backpack:WaitForChild("myTool", 5)

--optionally also adding
if not tool then print(player.Name, "has no tool!") end

I suspect this has to do with StarterGear. Because, if you create a server script that parents a tool to the players backpack when they join, this WaitForChild issue does not occur.