Hello!
I feel stupid asking this because I’ve used modules so many times but I can’t seem to get the table to return the proper result for some reason?
I have a module called UIUtil which is a UI utility module, it handles opening and closing UIs.
I have a function called “RegisterUI” which recognizes the UI, creates necessary connections etc, and most importantly adds it to a table to save the state.
However, when I require it from the command bar, the OpenUIs table just clears.
It should be a dictionary where the frame is the index and the value is a bool dictating whether it’s open or not.
print(require(game.ReplicatedStorage.Modules.UIUtil)) -- OpenUIs table is {}
Module:
local tweenService = game:GetService('TweenService')
local userInputService = game:GetService('UserInputService')
local module = {
['CreateNotice'] = function(self, successful: boolean, returnTable: { -- not important
promptStatus: boolean;
notice: string;
})
script.Parent.Enabled = returnTable.promptStatus
if returnTable.notice then
end
end;
['OpenUIs'] = {}; -- table where they should be added
['RegisterUI'] = function(self, uiObject: Frame, initialState: boolean?) -- function that adds to the table
local alreadyRegistered = self.OpenUIs[uiObject] ~= nil
if alreadyRegistered then
return warn(uiObject, 'is already registered!')
end
self.OpenUIs[uiObject] = initialState == true
print(self.OpenUIs)
for i,v in ipairs(uiObject:GetDescendants()) do
if v:IsA('GuiButton') and v.Name == 'CloseButton' then
v.MouseButton1Click:Connect(function()
self:Close()
end)
elseif v:IsA('ObjectValue') and v.Name == 'OpenFrame' then
v.Parent.MouseButton1Click:Connect(function()
self:Open(v.Value)
end)
end
end
if initialState then
self:Open(uiObject)
end
end;
['OpenByName'] = function(self, name)
print(self.OpenUIs)
for i,v in pairs(self.OpenUIs) do
if i.Name == name then
self:Open(i)
end
end
end,
['Open'] = function(self, uiObject)
if self.OpenUIs[uiObject] == nil then
return warn(uiObject, 'isn\'t registered!')
end
for i: Frame,v: boolean in pairs(self.OpenUIs) do
if v and i ~= uiObject then
self.OpenUIs[i] = false
tweenService:Create(i, TweenInfo.new(0.5), {Position = UDim2.new(0.5,0,-0.5,0)}):Play()
end
end
self.OpenUIs[uiObject] = true
print('a')
tweenService:Create(uiObject, TweenInfo.new(0.5), {Position = UDim2.new(0.5,0,0.5,0)}):Play()
end;
['Close'] = function(self)
for i,v in pairs(self.OpenUIs) do
if v then
tweenService:Create(i, TweenInfo.new(0.5), {Position = UDim2.new(0.5,0,-0.5,0)}):Play()
self.OpenUIs[i] = false
if i:FindFirstChild('OpenOnThisFrameClosed') then
self:Open(i)
end
end
end
end;
}
module.UserInputServiceInputBeganConnection = module.UserInputServiceInputBeganConnection or userInputService.InputBegan:Connect(function(input, gameProcessedEvent)
if gameProcessedEvent then
return
end
if input.KeyCode == Enum.KeyCode.Backspace or input.KeyCode == Enum.KeyCode.Escape then
module:Close()
end
end)
return module
Any ideas?