Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
✓ ANSWER ACCEPTED

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

--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

✓ Accepted answer

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)

2 comments

0

Thank you! I didn't think of the delay it helped me so much :D

0

No problem. :)

This discussion is preserved as it was. New answers, comments, and votes are closed.