What do you want to achieve? Keep it simple and clear!
I want for there to only be allowed one connection at a time, instead of them stacking.
What is the issue? Include screenshots / videos if possible!
When the connection disconnects it doesn’t work again.
What solutions have you tried so far? Did you look for solutions on the Developer Hub?
A lot of research and going on Events
local button = script.Parent
local remoteEvent = game.ReplicatedStorage.remoteEvents.boothEvents.clickedBoothButton
local connection
local function onClicked()
local layoutOrder = button.LayoutOrder
remoteEvent:FireServer(layoutOrder, button.Name)
connection:Disconnect()
end
connection = button.MouseButton1Click:Connect(onClicked)
Just like @bytesleuth said. Once you disconnect a connection, it will no longer work. It needs to stay connected, otherwise it won’t have any function to run since it’s not connected with one.
Should I do something else than disconnecting it then? I just don’t want it to be stacking up, it results in it being fired multiple times after one click.
From what I’ve read you just want to implement a simple debounce.
local debounce = false
local function onClicked()
if debounce then return end
debounce = true
-- insert anything
task.wait(1) -- set 1 to whatever cooldown
debounce = false -- re-enables function
end
“I tried that, but it does the same thing, I want it to still be able to be clicked after it is clicked once. Let me explain better.”
I’m pretty sure he just wants to prevent the event from being fired too much. Adding debounce is not bad practice. You should only use :Disconnect or .Once when you really want to have it fired only once. If you keep disconnecting and re-connecting, it is far less efficient, as it would have to be compiled all over again.
I apologize if I don’t explain well, my issue is that the event is stacking ontop of eachother. If I click the button once, it returns as it was clicked once, but after clicking it once if I click it again it returns that it was clicked twice, separate from the first time it was clicked.