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

Debounce not working ?

as the title says ? why doesn't it woooork ?? help please.. thx :3

debounce = true

function Click(mouse)
debounce = false
game.Players.LocalPlayer.Character.Head.Scream:Play()
wait(2.3)
debounce = true

end


script.Parent.MouseButton1Down:connect(Click)

1 comment

2 answers

✓ Accepted answer

Let's see here...

debounce = true

function Click(mouse)
	debounce = false
	game.Players.LocalPlayer.Character.Head.Scream:Play() --Where's the conditional statement to prevent this from happening?
	wait(2.3)
	debounce = true
end

script.Parent.MouseButton1Down:connect(Click)

Keep in mind that "debounce" is not a key word. Debounce isn't built into Lua, it's just an idea that gives functions cooldown. We could replace the word "debounce" with whatever we want.

the_function_is_allowed_to_happen = true

function onClick() --The mouse isn't being used in the function, so we need no arguments here.
	if the_function_is_allowed_to_happen == true then --If we can call the function
		the_function_is_allowed_to_happen = false --We can't call it again while it's active
		game.Players.LocalPlayer.Character.Head.Scream:Play()
		wait(2.3)
		the_function_is_allowed_to_happen = true --The function completed its task, now we can call it again.
	end
end

script.Parent.MouseButton1Down:connect(Click)

1 comment

0

oh darn i forgot about that! sorry!

You need to verifie if your variable is false before, for a more nicier version you can you my :) exemple:

local allow_to_run_the_function_depended_of_this_variable = false

function noLoop()
	if not allow_to_run_the_function_depended_of_this_variable then
		return
	end
	allow_to_run_the_function_depended_of_this_variable = true
	print('hi')
	wait(1)
	allow_to_run_the_function_depended_of_this_variable = false
end

script.Parent.Click:connect(noLoop)

It will wait one seconde before you can use it back theres your code:

local debounce = false

function Click(mouse)
	if not debounce then
		return
	end
	debounce = true
	game.Players.LocalPlayer.Character.Head.Scream:Play()
	wait(2.3)--wait 2 secondes before use it back
	debounce = false
end


script.Parent.MouseButton1Down:connect(Click)

2 comments

0

I already solved it, but thanks

0

np, I more love my version xD

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