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

How would I add debounce to this click detector script?

I'm very new to scripting, here is the script

clickDetector = game.workspace.Box.top.ClickDetector

function onMouseClick() game.Workspace.Box.bottom.Transparency = 0 game.Workspace.Box.top.Transparency = 1

		local num = math.random(1,5)

		if num == 1 then

			print("1")

		elseif num == 2 then

			print("2")

		elseif num == 3 then

			print("3")

		elseif num == 4 then

			print("4")

		elseif num == 5 then

			print("5")
		
	end
wait(3)
game.Workspace.Box.bottom.Transparency = 1
game.Workspace.Box.top.Transparency = 0

end clickDetector.MouseClick:connect(onMouseClick)

1 comment

0

not sure why it broke the script up into different areas ^

1 answer

✓ Accepted answer

It us fairly easy to make a debounce:

clickDetector = game.workspace.Box.top.ClickDetector

loal debounce = true

function onMouseClick() 
if debounce then
debounce = false
game.Workspace.Box.bottom.Transparency = 0 game.Workspace.Box.top.Transparency = 1

	        local num = math.random(1,5)
	 
	        if num == 1 then
	 
	            print("1")
	 
	        elseif num == 2 then
	 
	            print("2")
	 
	        elseif num == 3 then
	 
	            print("3")
	 
	        elseif num == 4 then
	 
	            print("4")
	 
	        elseif num == 5 then
	 
	            print("5")
	 
	    end
	wait(3)
	game.Workspace.Box.bottom.Transparency = 1
	game.Workspace.Box.top.Transparency = 0
	debounce = true
	end
end clickDetector.MouseClick:connect(onMouseClick)

Please note, I wrote this answer on mobile after waking up, so if there is any problem with this please tell me.

4 comments

0

thank you so much

0

No problem.

0

Accepted for you; they left you on read lmfao.

0

@Ziffixture Thanks for the accept!

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