Debounce STILL not working (for mouseclick)

So I made a topic on this a few days ago and many people tried, but we were not able to solve the issue. (The old topic)

So basically I have this:

plrsGui.speechFrame.speech.MouseButton1Click:Connect(function()
    if not deb2 then
        deb2 = true
        print("Clicked")
        --scroll()
    else
        wait(1)
        deb2 = false
    end
end)

Clicked prints more than once, but a different amount every time! Please help!

your problem is the

else
deb2 = false

part. If deb2 is equal to false, it will print clicked, but if it is equal to true, then the script will turn it to false. Just remove that part.

If I do that then first of all it for some reason will still print clicked more than once, and second the user wont be able to click again

The version you had in the old topic should be correct.

local deb2 = false
plrsGui.speechFrame.speech.MouseButton1Up:Connect(function()
	if not deb2 then
		deb2 = true
		print("Clicked")
		--scroll()
		wait(2)
		deb2 = false
	end
end)

If it’s printing multiple times per click then there might be multiple functions connected to this one event.

1 Like

I was thinking that, but when I tried to use the disconnect thingy it still didnt fix anything, maybe I was doing it wrong?

You shouldn’t have to disconnect anything. Maybe look through your other scripts to make sure only one function is connected to that button event.

Nope I guess I was just using the disconnect wrong last time I tried it because this time I got it to work, the reason it gets connected multiple times is because this is in a touched event! I honestly don’t know what I did different this time when it comes to disconnecting but it works so im not complaining. It’s working perfectly now!

For anybody that comes across this in the future, the problem is this is in a touched event so it gets hooked up multiple times, so each time you touch it you have to make sure there is no other connection, or disconnect the other connection, this is how I solved it:

local connection

invisWall.Touched:Connect(function(hit)
    -- More code (not important for this)
    if connection then
	   connection:Disconnect()
    end

    connection = plrsGui.speechFrame.speech.MouseButton1Up:Connect(function()
					if not deb2 then
						deb2 = true
						scroll() -- Replace with your thing
						wait(0.5)
						deb2 = false
					end
				end)
end)