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
 

Re: How to add debounce to an onTouch script?

Previous Thread :: Next Thread 
SirSparkleTime is not online. SirSparkleTime
Joined: 22 Sep 2012
Total Posts: 12472
09 Jul 2014 04:17 PM
I scripted a block to do damage every time you touch it, but how do I add debounce to make sure that it doesn't kill me instantly every time?

Here is the script already:

function onTouch(part)
local Toucher = part.Parent:FindFirstChild("Humanoid")

if Toucher ~= nil then
Toucher.Health = -50

end

end

block = script.Parent
block.Touched:connect(onTouch)
Report Abuse
AnonyAnonymous is not online. AnonyAnonymous
Joined: 23 Jun 2013
Total Posts: 6332
09 Jul 2014 04:18 PM
Debounce = false
function onTouch(part)
if not Debounce then
Debounce = true
local Toucher = part.Parent:FindFirstChild("Humanoid")
if Toucher ~= nil then
Toucher.Health = -50
wait(3)
Debounce = false
end
end
end
block = script.Parent
block.Touched:connect(onTouch)
Report Abuse
Tynexx is not online. Tynexx
Joined: 11 Jul 2012
Total Posts: 1559
09 Jul 2014 04:18 PM
db =1
function onTouch(part)
if db==1 then
db= 0
local Toucher = part.Parent:FindFirstChild("Humanoid")

if Toucher ~= nil then
Toucher:TakeDamage(50)
db = 1
end
end
end

block = script.Parent
block.Touched:connect(onTouch)
Report Abuse
sayhisam1 is not online. sayhisam1
Joined: 25 Nov 2009
Total Posts: 2092
09 Jul 2014 04:19 PM

function onTouch(part)
local Toucher = part.Parent:FindFirstChild("Humanoid")

if Toucher ~= nil and debounce == false then
debounce = true

Toucher.Health = -50

debounce = false

end

end

block = script.Parent
block.Touched:connect(onTouch)
Report Abuse
SirSparkleTime is not online. SirSparkleTime
Joined: 22 Sep 2012
Total Posts: 12472
09 Jul 2014 04:20 PM
Yay thank you. The debounce almost forms a "sandwich" around the function part of the script
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