Debounce not working

Yes I’ve made debounces before and Im not sure why this one won’t work.

Simple stuff you click the button its supposed to call the function, but only 1 time, until the cooldown finishes then you will be able to click again!

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

Also yes I know I commented out the function

Also It printed clicked 13 times!

You litterally set the debounce to false at the end of the function. How didnt you notice that?

Where is the variable deb2 stated in the script? if it’s like this:

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

then it wont work, stating it like this however:

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

that should work, Otherwise, I have no clue why it isn’t functioning properly.

your joking right?
character limit

He said he wanted to only run it one time, so it would be

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

It would then get stuck running once since it never sets deb2 to false again, and he wants it to run multiple times, with a wait time each run.
EDIT: NEVERMIND! read it wrong, sorry! You’re correct, I thought he wanted it to run as many times as possible!

You legitimately set the debounce to false at the end of the script:

--scroll()
wait(2)
deb2 = false

No my bad @TheBigC10 you are correct I don’t want it to get stuck I just want it to only fire once at a time sorry, poor choice of words from me. Also deb2 is declared outside of the clicked function

No because then it would get stuck and you wont be able to move on to the next click

Yeah, that is odd, Lemme run it on my studio, and i’ll come back when I have an answer.

Okay great! Hopefully it’ll work

Hmmm, it’s working for me… So, you want the button to have a two second delay between pushes, right? if so, it should already work.

1 Like

Well it’s not actually gonna be 2 seconds but either way its not working for some reason

That’d odd, I don’t know why it isn’t working then, The script I supplied should work, Could you send the full script? (If it isn’t the whole thing already)

1 Like

Well the whole thing has a ton of irrelevant things but I’ll give what you need, there is a touched event on a part in the workspace, get the player using the hit and stuff, the plrsGui variable is refrence to player.PlayerGui

It makes the speechFrame inside of the plrsGui visible then sets up the click event on the text button inside of the speechFrame

why u dont use if deb2 == false isnt it better?

I’ve tried that and I got the same results :confused:

I believe not deb2 and deb2 == false do the exact same thing. : )

I’m sorry, I have no clue why it isn’t working properly. : (