Why is my debounce not working?

Self explanatory.

local debounce = false

UIS.InputBegan:Connect(function(input,isTyping)
if not isTyping then
if input.KeyCode == Enum.KeyCode.B and debounce == false then
debounce = true
game.SoundService.Music:Stop()

            game.SoundService.Scream:Play()
            spinVFX:FireServer()
            Spin:FireServer()


    end
end
1 Like

What exactly is not working about it? Is your debounce supposed to last forever or turn false again after a set period of time?

My debounce is supposed to make it so the player can only execute the function once. The thing is that’s not happening, it let’s me spam the “B” key and execute it however many times I want.

Your actual code is fine, it’s just not working as expected due to some tiny syntax errors - missing one end and a bracket to close your function. The following small changes will fix your code:

local debounce = false

UIS.InputBegan:Connect(function(input,isTyping)
    if not isTyping then
        if input.KeyCode == Enum.KeyCode.B and debounce == false then
            debounce = true
            game.SoundService.Music:Stop()

            game.SoundService.Scream:Play()
            spinVFX:FireServer()
            Spin:FireServer()
        end
    end
end)

Hope this helped :slightly_smiling_face:

1 Like