So I'm creating a lil system to allow Mouse and Keyboard, as well as gamepad to work in a GUI, by only creating necessary connections when entering a menu and having them removed on leaving the menu. Sounds good, but lets hold that thought, because leaving a menu and returning creates an additional connection! WOAH! So now every button press happens twice, which means if I wanted to change something from true to false, it goes, true>false>true again. Aghh! D:< Here is the basic structure:
local ScreenConnections = {}
function ChangeScreen(NewScreen)
if CurrentScreen ~= nil then
CurrentScreen.Visible = false
if CurrentSelection~=nil then
CurrentSelection.BackgroundTransparency = 1
CurrentSelection.BorderSizePixel = 1
PastScreen = CurrentScreen
end
end
print(#ScreenConnections)
if #ScreenConnections > 0 then
for _,i in pairs(ScreenConnections) do
i:disconnect()
end
end
CurrentScreen = NewScreen
CurrentScreen.Visible = true
CurrentSelection = nil
for _,i in pairs(CurrentScreen:GetChildren()) do
if i.ClassName == "TextButton" then
ScreenConnections[i.Name.."MouseEnter"] = i.MouseEnter:connect(function()SelectButton(i)end)
ScreenConnections[i.Name.."MouseLeave"] = i.MouseLeave:connect(function()SelectButton()end)
ScreenConnections[i.Name.."MouseClick"] = i.MouseButton1Click:connect(function()ActivateButton(i)end)
end
if CurrentScreen.Name == "Options" and i.ClassName == "Frame" then
local InSub = false
local butt = i:FindFirstChild("Header")
local info = i:FindFirstChild("Info")
local Enable = i:FindFirstChild("Enable")
local Scroll = i:FindFirstChild("Scroll")
local SubMenu = i:FindFirstChild("SubMenu")
ScreenConnections[i.Name.."MouseEnter"] = i.MouseEnter:connect(function()info.Visible = true end)
ScreenConnections[i.Name.."MouseLeave"] = i.MouseLeave:connect(function()info.Visible = false end)
--butt.MouseEnter:connect(function()SelectButton(butt) end)
--butt.MouseLeave:connect(function()SelectButton()end)
if Enable then
ScreenConnections[i.Name..Enable.Name.."MouseEnter"] = Enable.MouseEnter:connect(function()SelectButton(Enable)end)
ScreenConnections[i.Name..Enable.Name.."MouseLeave"] = Enable.MouseLeave:connect(function()Enable.BorderSizePixel = 0 end)
ScreenConnections[i.Name..Enable.Name.."MouseClick"] = Enable.InputBegan:connect(function(InObj) if InObj.UserInputType == Enum.UserInputType.MouseButton1 then
ActivateButton(Enable)
end
end)
Enable.BorderSizePixel = 0
end
if info then
info.Visible = false
end
if Scroll then
ScreenConnections[i.Name..Scroll.Name.."MouseDown"] = Scroll.InputBegan:connect(function(a)
if a.UserInputType == Enum.UserInputType.MouseButton1 and a.UserInputState == Enum.UserInputState.Begin then
MoveConn = Scroll.MouseMoved:connect(function(X) print("FOR NARNIA") UpdatePos(X,Scroll) wait(.2) print("") end)
end
end)
ScreenConnections[i.Name..Scroll.Name.."MouseUp"] = Scroll.InputEnded:connect(function()
local Min = Scroll:FindFirstChild("Min")
if Min then
if Scroll.Bar.Position.X.Offset < Min.AbsoluteSize.X then
Scroll.Bar.Position = UDim2.new(-1,Min.AbsoluteSize.X,0,0)
end
end
if MoveConn ~= nil then
MoveConn:disconnect()
MoveConn = nil
end
end)
end
end
end
end
ChangeScreen(Menu.Main)
Everything is properly connected, all functions fire, and it runs normally, but the table doesn't seem to be updated. This majorly sucks. Any idea what I've done wrong?

1 comment
I didn't know that, I've been doing # checks for all my tables since the dawn of time. Thanks!