towmater
|
  |
| Joined: 05 Jan 2007 |
| Total Posts: 1804 |
|
|
| 13 Jun 2014 08:24 PM |
| I get the purpose, but idk how to use it. |
|
|
| Report Abuse |
|
|
cntkillme
|
  |
| Joined: 07 Apr 2008 |
| Total Posts: 44956 |
|
|
| 13 Jun 2014 08:26 PM |
| http://wiki.roblox.com/index.php?title=Debounce |
|
|
| Report Abuse |
|
|
Dralian
|
  |
| Joined: 21 Mar 2013 |
| Total Posts: 7624 |
|
|
| 13 Jun 2014 08:28 PM |
The most basic way in my opinion to learn debounce is making a regen script.
|
|
|
| Report Abuse |
|
|
Malcolt3
|
  |
| Joined: 17 Dec 2009 |
| Total Posts: 11442 |
|
|
| 13 Jun 2014 08:28 PM |
You're basically just setting a variable that gets changed to true every time the event occurs and changed back to false after a certain amount of time. The event will only run if the variable is false, so it keeps some player from overloading on an event like a plane regen or whatever.
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) |
|
|
| Report Abuse |
|
|
|
| 13 Jun 2014 08:28 PM |
debounce = false
function touch(hit) if debounce == false then --you can rewrite this as if not debounce then debounce = true --does not allow anything to run now if hit.Parent:FindFirstChild("Humanoid") --looks for humanoid hit.Parent.Humanoid:TakeDamage(25) --damages humanoid by 25 end wait(5) --makes it so the function does not run anything until you wait 5 seconds debounce = false --function can run again end end end
script.Parent.Touched:connect(hit) |
|
|
| Report Abuse |
|
|