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