From 80d72f7b7abb8d05eaa1542f00c9f375ec41077a Mon Sep 17 00:00:00 2001 From: spoukyii <61633921+spoukyii@users.noreply.github.com> Date: Wed, 25 Nov 2026 13:23:08 -0800 Subject: [PATCH] fix(binder): skip instances that left the game before their added signal ran With deferred signals, CollectionService's added signal can run after the tagged instance was destroyed or removed, so the binder constructed its class on an instance with no parent and no children, then unbound it at once. On a client this happens whenever the server adds and destroys a tagged model within one replication batch, and a constructor that reads the model's children errors. Bug: attempt to index nil with 'DisplayDistanceType' --- src/binder/src/Shared/Binder.Loading.spec.lua | 23 +++++++++++++++++++ src/binder/src/Shared/Binder.lua | 5 +++- 2 files changed, 27 insertions(+), 1 deletion(-) diff --git a/src/binder/src/Shared/Binder.Loading.spec.lua b/src/binder/src/Shared/Binder.Loading.spec.lua index 3e826a67e6b..67693c85d35 100644 --- a/src/binder/src/Shared/Binder.Loading.spec.lua +++ b/src/binder/src/Shared/Binder.Loading.spec.lua @@ -48,4 +48,27 @@ describe("Binder load abandonment", function() controller:Destroy() end) + + it("does not construct for an instance destroyed before its added signal runs", function() + local controller = BinderTestUtils.setup() + + local strays = 0 + local binder = controller.addBinder(function(inst) + if not inst:IsDescendantOf(game) then + strays += 1 + end + return {} + end) + controller.initServiceBag() + + local inst = controller.newInstance() + binder:Tag(inst) + inst:Destroy() + task.wait() + + expect(strays).toEqual(0) + expect(binder:Get(inst)).toBeNil() + + controller:Destroy() + end) end) diff --git a/src/binder/src/Shared/Binder.lua b/src/binder/src/Shared/Binder.lua index 3c42887cd41..ec8f048b804 100644 --- a/src/binder/src/Shared/Binder.lua +++ b/src/binder/src/Shared/Binder.lua @@ -218,7 +218,10 @@ function Binder.Start(self: Binder) end self._maid:GiveTask(CollectionService:GetInstanceAddedSignal(self._tagName):Connect(function(inst) - self:_add(inst) + -- A deferred signal can deliver an instance that was destroyed or removed after it was tagged. + if inst:IsDescendantOf(game) then + self:_add(inst) + end end)) self._maid:GiveTask(CollectionService:GetInstanceRemovedSignal(self._tagName):Connect(function(inst) self:_remove(inst)