Unique References Debugging

There’s instances in the unique references that I can’t figure out how to clean.
I have a script that basically makes cutscenes for the player, and the player instance appears in the unique references for some reason.

I have a picture to show u, and I labeled what line it occurs in.

function CutsceneServiceServer.init(self: CutsceneServiceServer)
	for _, player : Player in Players:GetChildren() do
		player.CharacterAdded:Connect(function() -- Line where it errors
			self:PlayCutscene("Blackhole", player)
		end)
	end
	
	Players.PlayerAdded:Connect(function(player)
		player.CharacterAdded:Connect(function()
			self:PlayCutscene("Blackhole", player)
		end)
	end)
	
	Players.PlayerRemoving:Connect(function(player)
		if self.PlayersInCutscene[player.UserId] then
			
			local cutsceneInfo = CutscenseInfo.Scenes[player.UserId]
			self.PlayersInCutscene[player.UserId] = nil
		else
			print("Not in scene")
		end
	end)
endzs 

Is Workspace.PlayerCharacterDestroyBehavior enabled? The engine by default doesn’t properly destroy player and character objects when the player dies or leaves, so connections made to them never disconnect.

In your case, the references to player in your callbacks would leak because the player and character are never destroyed, which means their connections never disconnect and their callback functions (and references) never garbage collect.

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.