So I created a UI managing module which allows me to add screenuis to it and automatically open them up with a key passed through. This is what the function looks like to add a new UI to the manager.
function UIManager:AddUI(UIName, UIObject, Hotkey, ShowCallback, HideCallback)
self.UIs[UIName] = {Name = UIName, UI = UIObject, Hotkey = Hotkey, ShowCallback = ShowCallback, HideCallback = HideCallback, disabled = false};
end
Thing is, it works great for the first two UIs I add, which are the Inventory and Settings UI.
Settings UI
self.Controllers.UIManager:AddUI("Settings", self.SettingsFrame.Parent.Parent, Enum.KeyCode.P, function()
script.InventoryOpen:Play();
end, function()
script.InventoryOpen:Play();
end)
Inventory UI
self.Controllers.UIManager:AddUI("Inventory", self.InventoryUI.InventoryUI, Enum.KeyCode.G, function()
script.InventoryOpen:Play();
end, function()
script.InventoryOpen:Play();
end)
But, when I try to add this other UI, a Faction menu, I get this error:
Players.WorldPosition.PlayerScripts.Aero.Controllers.UIManager:15: attempt to index nil with 'Factions'
Creating the tables inside self.UIs with the UIName has always worked, up until this point. For some reason it’s trying to index it, even though it should just be creating the table, like it did the past 2 times I used this function.
Here’s the code I’m using to try and add the Faction UI to the UI manager.
self.Controllers.UIManager:AddUI("Factions", FactionMenu, Enum.KeyCode.K, function()
script.Open:Play();
end, function()
script.Open:Play();
end)
I tested to see if what I thought is correct, by it is trying to index instead of create, and I think I am correct. I added
self.UIs["Test"] = {};
Which result in the same error. I’m confused as to why it’s able to create two values in self.UIs but after the third, it’s starts acting differently.