Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

The event in my function seems to run twice?

Asked by
ExcelUp 24
4 years ago
Edited 4 years ago

I have a function called "Menu. Whenever it is called, toward the end, if a text button is pressed, it is to call another function, depending on the name of the text button. The event seems to run once, when pressed once initially, but when Menu is re-called later within the code, the event seems to run twice them then onward whenever the function is re-called. I've tried adding debounces; everything: to no avail.

The arguement "Screen" holds the directory of a SurfaceGui, located within a Part, within the Workspace. The arguement "TerminalInfo" is a table defined elsewhere within the code. The arguement "Player" is also defined elsewhere within the code, which is the player using the Gui. The script is a server script, located in ServerScriptService. The functions "display_items" and "hide_items" are functions defined elsewhere within the script that merely show or hide the elements within certain areas of the Gui.

function Menu(Terminal, TerminalInfo, Player, Screen)
    Screen.Return.Visible = false
    table.insert(TerminalInfo.BrowseHistory, "Menu")
    local Folder = Screen.Menu.Frame
    TerminalInfo.CurrentDirectory = Folder
    Folder.Visible = true
    display_items(Folder)
    for _, Item in pairs(Folder:GetChildren()) do
        if Item.ClassName == "TextButton" then
            Item.MouseButton1Click:Connect(function()
                print("Event")
                hide_items(Folder)
                if Item.Name == "Information" then
                    print("Selecting Directory")
                    Information(Terminal, TerminalInfo, Player, Screen)
                end
            end)            
        end
    end
end

Answer this question