Decided to make this on a whim. I saw that some other people have taken shots at this before, but still rely on task.wait(). This one implements a signal that handles timeouts and child added events.
return function(instance, name, timeout)
local bindable = Instance.new("BindableEvent")
local result = instance:FindFirstChildWhichIsA(name)
local connection = instance.ChildAdded:Connect(function(...)
bindable:Fire(...)
end)
if timeout then
task.delay(timeout, bindable.Fire, bindable, true)
end
while not result do
local child = bindable.Event:Wait()
if child == true then
break
end
if child:IsA(name) then
result = child
end
end
connection:Disconnect()
bindable:Destroy()
return result
end
