Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

So I was messing around in Roblox Studio and trying out debounce and it dosen't work?

Asked by 4 years ago
Edited 4 years ago

--I also tried one from Dev Hub but that debounce didn't work either, have they updated this? and can someone link me a working debounce article or something

from dev hub:

local buttonPressed = false
--Store whether the button is pressed in a local variable

workspace.Button.Touched:Connect(function(hit)
    if not buttonPressed then
    -- Is it not pressed?

        buttonPressed = true
        -- Mark it as pressed, so that other handlers don't execute

        print("Button pressed")
        -- Do Stuff

        buttonPressed = false
        -- Mark it as not pressed, so other handlers can execute again
    end
end)

This code prints it over and over again?? and the same thing with my test code (similar).

1 answer

Log in to vote
1
Answered by
JakyeRU 637 Moderation Voter
4 years ago
Edited 4 years ago

Hello. That's because there is no wait in your debounce. Your value buttonPressed will become instantly false and repeat if you are touching the brick. Try this:

local buttonPressed = false

workspace.Button.Touched:Connect(function(hit)
    if not buttonPressed then
        buttonPressed = true
        print("Touched!")
        wait(5) -- Delay
        buttonPressed = false
    end
end)
0
Thank you! I didn't think of the delay it helped me so much :D Freddan2006YT 88 — 4y
0
No problem. :) JakyeRU 637 — 4y
Ad

Answer this question