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

How to put a debounce to 2 functions?

I don't want players to be spamming clicks so I want to put a debounce to MouseButton1Down and MouseButton1Up. Thank you!

script.Parent.Equipped:Connect(function(mouse)

		mouse.Button1Down:Connect(function()
			--Block of codes
		end)

		mouse.Button1Up:Connect(function()
			--Block of codes
		end)
end)

2 answers

✓ Accepted answer

Hope this helps:

local deb = false
script.Parent.Equipped:Connect(function(mouse)

        mouse.Button1Down:Connect(function()
		if not deb then
			deb = true
            --Block of codes
			deb = false
		end
        end)

        mouse.Button1Up:Connect(function()
		if not deb then
			deb = true
            --Block of codes
			deb = false
		end
        end)
end)

If it answered your question, please accept the answer :)

1 comment

0

thanks

Sure thing.

  1. You don't need separate connections to achieve this, a single debounce is just fine.
script.Parent.Equipped:Connect(function(mouse)
	local debounce = false

        mouse.Button1Down:Connect(function()
	    if debounce then return end
	    debounce = true

            --Block of codes

	    debounce = false
        end)

end)

1 comment

0

i mean in my case, button1down and button1up has different function so...

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