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