Issue with admin panel

Hi, I’m making an admin panel called VisionHub v2 and I’m having issues with the command system, the system works of a GUI based interface and commands are ran through a frame that hold arguments that apply to the command at hand.

I’m trying to achieve a function based module system, where the commands are ran though individual module scripts, and the commands are loaded in the panel.

My issue is that when i run the command submit function, its running one more time each time, screenshots below to better understand:

In the first screen shot, I click the kill button once and submitted once, it worked normally,
In the second i had clicked the kill button twice (INCLUDING THE FIRST TIME) and it ran the command twice

Screenshots
The Issue

Command Button Clicked Once And Submitted Once: (Output)


Command Button Clicked Twice And Submitted Once: (Output)

Scripts

Button Pressed
image

LoadArguments function (will load arguments to arguments menu)

RunCommand function
image

1 Like

Does your script repeat the action the more you use it? (ex. If you used it 3 times, it will repeat 3 times in one click)

If that’s the case, maybe your script adds another event listener without disconnecting the original one? (ie. multiple Button.Activated connections)

When you use :Connect(), it creates a new connection each time it’s called. Basically, if you click the button twice, two connections are created, and the function will run twice when the event is triggered. To fix this, simply disconnect the previous connections before creating new ones.

do you know where i could put :Disconnect?

do you know where i could put :Disconnect ?

Try this?

local cancelButtonConnection
local submitButtonConnection

local function LoadArguments(command: ModuleScript, callback)
    argumentsFrame.Toggled.Value = false
    tTable.ToggleArguments()

    if cancelButtonConnection then
        cancelButtonConnection:Disconnect()
    end

    if submitButtonConnection then
        submitButtonConnection:Disconnect()
    end

    cancelButtonConnection = ArgumentsFrame.CancelButton.Button.MouseButton1Click:Connect(function()
        callback()
        argumentsFrame.Toggled.Value = true
        tTable.ToggleArguments()
        valuesF.SelectedCommand.Value = nil
    end)

    submitButtonConnection = argumentsFrame.SubmitButton.Button.MouseButton1Click:Connect(function()
        valuesF.SelectedCommand.Value = command
        RunCommand()
        argumentsFrame.Toggled.Value = true
        tTable.ToggleArguments()
    end)
end

tysm bro
I’ve been working on this for a few hours and i’ve never really used :Disconnect() so i dont really know how to use it, again thank you bro

i hope you have a good day
:smiley:

No problem! You have a good rest of your day, I’ll go to sleep now :sweat_smile:.

:v:

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.