diff --git a/Pronghorn/New.luau b/Pronghorn/New.luau index cc1c8d4..69ac3c1 100644 --- a/Pronghorn/New.luau +++ b/Pronghorn/New.luau @@ -410,27 +410,41 @@ end --- Creates and returns an InstanceStream. --- @return InstanceStream -- The new InstanceStream. function New.InstanceStream(): InstanceStream<...any> + local replicators: {[Player]: RemoteEvent} = {} + local actions: InstanceStream<...Instance> = { Instances = {}; Start = function(self: InstanceStream<...Instance>, players: Player | {Player}, instances: {Instance}): string if IS_CLIENT then error("InstanceStream.Start cannot be called on the client", 0) end + table.clear(self.Instances) + for index, instance in instances do + self.Instances[index] = instance + end + local uid = `{HttpService:GenerateGUID(false)}_{#instances}` for _, player in (if type(players) == "table" then players else {players}) :: {Player} do - local container = New.Instance("RemoteEvent", `__instanceStream_{uid}`) :: RemoteEvent + if not player.Parent then continue end - for _, instance in instances do - table.insert(self.Instances, instance) - New.Instance("ObjectValue", container, {Value = instance}) + local replicator = New.Instance("RemoteEvent", `__instanceStream_{uid}`) :: RemoteEvent + + if replicators[player] then + replicators[player]:Destroy() end + replicators[player] = replicator - container.Parent = player.PlayerGui + for _, instance in instances do + New.Instance("ObjectValue", replicator, {Value = instance}) + end - container.OnServerEvent:Once(function() - container:Destroy() + replicator.OnServerEvent:Once(function() + replicator:Destroy() + replicators[player] = nil end) + + replicator.Parent = player.PlayerGui end return uid diff --git a/Pronghorn/init.luau b/Pronghorn/init.luau index aba6901..55ced08 100644 --- a/Pronghorn/init.luau +++ b/Pronghorn/init.luau @@ -31,7 +31,7 @@ ║ ██████▀██▓▌▀▌ ▄ ▄▓▌▐▓█▌ ║ ║ ║ ║ ║ -║ Pronghorn Framework Rev. B73 ║ +║ Pronghorn Framework Rev. B74 ║ ║ https://github.com/Iron-Stag-Games/Pronghorn ║ ║ GNU Lesser General Public License v2.1 ║ ║ ║