generic image
Processing...
  • Games
  • Catalog
  • Develop
  • Robux
  • Search in Players
  • Search in Games
  • Search in Catalog
  • Search in Groups
  • Search in Library
  • Log In
  • Sign Up
  • Games
  • Catalog
  • Develop
  • Robux
   
ROBLOX Forum » Game Creation and Development » Scripting Helpers
Home Search
 

How does one debounce?

Previous Thread :: Next Thread 
towmater is not online. 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 is not online. 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 is not online. 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 is not online. 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
SenseiWarrior is not online. SenseiWarrior
Joined: 09 Apr 2011
Total Posts: 12140
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
Previous Thread :: Next Thread 
Page 1 of 1
 
 
ROBLOX Forum » Game Creation and Development » Scripting Helpers
   
 
   
  • About Us
  • Jobs
  • Blog
  • Parents
  • Help
  • Terms
  • Privacy

©2017 Roblox Corporation. Roblox, the Roblox logo, Robux, Bloxy, and Powering Imagination are among our registered and unregistered trademarks in the U.S. and other countries.



Progress
Starting Roblox...
Connecting to Players...
R R

Roblox is now loading. Get ready to play!

R R

You're moments away from getting into the game!

Click here for help

Check Remember my choice and click Launch Application in the dialog box above to join games faster in the future!

Gameplay sponsored by:
Loading 0% - Starting game...
Get more with Builders Club! Join Builders Club
Choose Your Avatar
I have an account
generic image