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

How to add a debounce?

Asked by 8 years ago

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

Log in to vote
1
Answered by 8 years ago

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

Ad
Log in to vote
0
Answered by
xuefei123 214 Moderation Voter
8 years ago

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!

0
Thanks very much! It worked! ScriptFusion 210 — 8y

Answer this question