Deleting Function References Inside of Module Scripts

Good afternoon everyone, I am currently working on a module script to create dropdowns and I was working on certain functions inside of the module, and one of the functions I wanted to try to do was :DestroyReference() the goal of this function is to clear the whole self table and make the dropdown no longer be able to be acessed through code, so that this could help with performance or other means; however, when I try to do simple code like:

for i, _ in self do
	i = nil
end

and incase I did that wrong, I tried it the other way with for _, x do…

That didn’t clear the table, and I don’t understand how to, I am very new to using metatables and maybe I am removing it incorrectly, but is there another way to remove all the things inside of the self table more effectively than calling EVERYTHING withinside of it? Also with this :DestroyReferences() function, I want to clear the other functions from it like :AnimateMenu() and :DisconnectAll(), is there a way I can do this?

Module Code:

local spaceInBetween: number = script.DropDownSpace.Value
local tweenTime: number = script.TweenTime.Value
local EasingDirection = Enum.EasingDirection.In
local EasingStyle = Enum.EasingStyle.Linear

local dropdown = {}
dropdown.__index = dropdown

-- This function is used for checking if it matches the certain UI paramters and returns a boolean
local function objectParameter(obj: GuiObject): boolean
	if obj:IsA("TextButton") or obj:IsA("ImageButton") or obj:IsA("TextLabel")
		or obj:IsA("ImageLabel") or obj:IsA("TextBox") or obj:IsA("Frame") or obj:IsA("ScrollingFrame") then
		return true
	else
		return false
	end
end

local function handleOthers(dropDownBtns, dropdownContent, moveOthers: {}, open1: boolean, btn: TextButton)
	-- No stealing
end

function dropdown.New(dropDownBtns, dropDownContents, autoClose, moveOthers, advancedSettings)
	local self = setmetatable({}, dropdown)

	self.dropDownBtns = dropDownBtns
	self.dropDownContents = dropDownContents

	self.autoClose = autoClose or true
	self.moveOthers = moveOthers or {}
	self.dataHolder = {}
	self.debounce = false

	self.ConnectionHolder = {}

	self.AdvancedSettings = advancedSettings or {}
	if advancedSettings ~= nil then
		self.tweenTime = advancedSettings.TweenTime or script:WaitForChild("TweenTime").Value
		self.spaceInBetween = advancedSettings.DropDownSpace or script:WaitForChild("DropDownSpace").Value
		self.EasingStyle = advancedSettings.EasingStyle or Enum.EasingStyle.Linear
		self.EasingDirection = advancedSettings.EasingDirection or Enum.EasingDirection.In
	else
		self.tweenTime = script:WaitForChild("TweenTime").Value
		self.spaceInBetween = script:WaitForChild("DropDownSpace").Value
		self.EasingStyle = Enum.EasingStyle.Linear
		self.EasingDirection = Enum.EasingDirection.In
	end

	return self
end

local debounce = false

-- Connects the actual dropdown to work!
function dropdown:AnimateMenu() -- dropDownBtns: Folder, dropDownContents: Folder, autoClose: boolean, moveOthers: {}, ADVANCED_SETTINGS: {}

	local dropDownBtns = self.dropDownBtns
	local dropDownContents = self.dropDownContents
	local autoClose = self.autoClose
	local moveOthers = self.moveOthers
	local dataHolder = self.dataHolder

	local ADVANCED_SETTINGS = self.AdvancedSettings

	-- All of code in here works, but deleted for no stealing!
end

-- This functions disconnects all the buttons attached to it
function dropdown:DisconnectAll()
	local connectionTable = self.ConnectionHolder

	for _, x in connectionTable do
		x:Disconnect()
	end

	self.ConnectionHolder = {}
end

function dropdown:DestroyReference()
	local connectionTable = self.ConnectionHolder

	for _, x in connectionTable do
		x:Disconnect()
	end

	for i, _ in self do
		i = nil
	end

	self.dropDownBtns = nil
	self.dropDownContents = nil
	self.moveOthers = nil
	self.dataHolder = nil
	self.AdvancedSettings = nil
	self.ConnectionHolder = nil
	self.tweenTime = nil
	self.spaceInBetween = nil
	self.EasingStyle = nil
	self.EasingDirection =nil
	
	-- How do I disconnect the functions here
end

return dropdown

I believe you can just clear the table.

table.clear(self)

Also, I recommend looking into cleaning modules like maid or trove.
Here is a link to the cleaning service Trove:
Trove Api

Ok, yes that works and I am glad, but I am going to make this be like a community product, so when it clears all references, is there a way it can clear like all the functions from autotype after than :DestroyReferences() is called?

autoTypeWithDropdown

If you found the trove library interesting, there is a method in trove called :Add().

So for example, let’s use the function: dropdown:AnimateMenu(). You can do this:

local Trove = require(path.to.Trove)

-- Initialize trove instance
self._trove = Trove.new()
self._trove:Add(dropdown, "AnimateMenu") -- First param takes the table, second param takes the function within table

-- So now when you want to destroy references, you can just call self._trove:Clean()
function dropdown:DestroyReference()
    self._trove:Clean()
end

If you do not want to use the Trove library, I think you can just call self and then the function, and set it to nil.

-- Setting AnimateMenu to nil
self.AnimateMenu = nil

Even using the Trove and self.AnimateMenu = nil, the function can still be called. I’m not sure why it is that way, but I’m still getting error messages when it is fired after deleting all references. Any other ideas?