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)
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.
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