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

How to add a debounce?

So I have this heal part thing, but I would like a debounce on it. Any suggestions, or ideas??

script.Parent.Touched:connect(function(p)
if p.Parent:FindFirstChild("Humanoid") then
p.Parent.Humanoid.Health = 100
end
end)

If I knew a basic debounce script, I could add this to GUI's and stuff like that, but I don't know how to. Any help?

2 answers

✓ Accepted answer

This should work.... :P:P TROLOLOL

I think I understand what you mean. I think it would be something like this,

local buttonPressed = false
--Store whether the button is pressed in a local variable
 
Workspace.Button.Touched:connect(function(hit)
    if not buttonPressed then
    -- Is it not pressed?
 
        buttonPressed = true
        -- Mark it as pressed, so that other handlers don't execute
 
        print("Button pressed")
        wait(1)
        print("Hi :D")
        -- Do Stuff
 
        buttonPressed = false
        -- Mark it as not pressed, so other handlers can execute again
    end
end)

Hope this helps you!

1 comment

0

Thanks very much! It worked!

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