local I={}local h=Instance.new("\066\105\110\100\097\098\108\101\069\118\101\110\116")function TryRemoveChildWithVerifyingIsCorrectType(h)if waitChildren[h.Name]and h:IsA(waitChildren[h.Name])then waitChildren[h.Name]=nil I[h.Name]=h numChildrenRemaining=numChildrenRemaining-1 end end for I,h in pairs(EventFolder:GetChildren())do TryRemoveChildWithVerifyingIsCorrectType(h)end if numChildrenRemaining>0 then local I=EventFolder.ChildAdded:connect(function(I)TryRemoveChildWithVerifyingIsCorrectType(I)if numChildrenRemaining<1 then h:Fire()end end)h.Event:wait()I:disconnect()h:Destroy()end EventFolder=I
-- waitChildren/EventFolder does not contain all the remote events, because the server version could be older than the client version.
-- In that case it would not create the new events.
-- These events are accessed directly from DefaultChatSystemChatEvents

local useEvents = {}

local FoundAllEventsEvent = Instance.new("BindableEvent")

function TryRemoveChildWithVerifyingIsCorrectType(child)
	if waitChildren[child.Name] and child:IsA(waitChildren[child.Name]) then
		waitChildren[child.Name] = nil
		useEvents[child.Name] = child
		numChildrenRemaining = numChildrenRemaining - 1
	end
end

for i, child in pairs(EventFolder:GetChildren()) do
	TryRemoveChildWithVerifyingIsCorrectType(child)
end

if numChildrenRemaining > 0 then
	local con = EventFolder.ChildAdded:connect(function(child)
		TryRemoveChildWithVerifyingIsCorrectType(child)
		if numChildrenRemaining < 1 then
			FoundAllEventsEvent:Fire()
		end
	end)

	FoundAllEventsEvent.Event:wait()
	con:disconnect()

	FoundAllEventsEvent:Destroy()
end

EventFolder = useEvents
