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 9 years ago

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

1script.Parent.Touched:connect(function(p)
2if p.Parent:FindFirstChild("Humanoid") then
3p.Parent.Humanoid.Health = 100
4end
5end)

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 9 years ago

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

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

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

01local buttonPressed = false
02--Store whether the button is pressed in a local variable
03 
04Workspace.Button.Touched:connect(function(hit)
05    if not buttonPressed then
06    -- Is it not pressed?
07 
08        buttonPressed = true
09        -- Mark it as pressed, so that other handlers don't execute
10 
11        print("Button pressed")
12        wait(1)
13        print("Hi :D")
14        -- Do Stuff
15 
16        buttonPressed = false
17        -- Mark it as not pressed, so other handlers can execute again
18    end
19end)

Hope this helps you!

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

Answer this question