Skip to content

Commit

Permalink
Check already streamed instances in addition to new descendants.
Browse files Browse the repository at this point in the history
  • Loading branch information
TheyCallMeRyan authored Jul 20, 2024
1 parent 2f2428a commit eeb396e
Showing 1 changed file with 8 additions and 3 deletions.
11 changes: 8 additions & 3 deletions lib/useStream.lua
Original file line number Diff line number Diff line change
Expand Up @@ -174,8 +174,8 @@ local function useStream(id: unknown, options: StreamOptions?): () -> (number?,
local options = normalizeOptions(options)
storage.queue = Queue.new()
storage.trackedInstances = {}

storage.addedConnection = Workspace.DescendantAdded:Connect(function(instance: Instance)
local function newDescendant(instance: Instance)
if instance:GetAttribute(options.attribute) ~= id then
return
end
Expand Down Expand Up @@ -204,7 +204,12 @@ local function useStream(id: unknown, options: StreamOptions?): () -> (number?,
for _, descendant in instance:GetDescendants() do
storage.queue:push(streamInEvent(descendant, true))
end
end)
end

storage.addedConnection = Workspace.DescendantAdded:Connect(newDescendant)
for _, instance: Instance in Workspace:GetDescendants() do
newDescendant(instance)
end

storage.removingConnection = Workspace.DescendantRemoving:Connect(
function(instance: Instance)
Expand Down

0 comments on commit eeb396e

Please sign in to comment.