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

Debounce not working ?

Asked by
Bulvyte 388 Moderation Voter
8 years ago

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)

2 answers

Log in to vote
1
Answered by
funyun 958 Moderation Voter
8 years ago

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)
0
oh darn i forgot about that! sorry! Bulvyte 388 — 8y
Ad
Log in to vote
2
Answered by 8 years ago

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)

0
I already solved it, but thanks Bulvyte 388 — 8y
0
np, I more love my version xD XToonLinkX123 580 — 8y

Answer this question