I'm wondering if I'm supposed to use debounce to temporarily disable the damage script, just so that 10 damage doesnt = 30 damage when you hit it 3 times too quickly. Also I'm wondering why I cant copy stuff from ROBLOX to my clipboard, it almost seems like there is a clipboard just for ROBLOX and I couldn't just copy and paste to post this question.
Damage = 10 function onTouch(hit) human = hit.Parent:FindFirstChild("Humanoid") if human ~=nil and human.Parent.color~=nil then script.Parent.Parent.Humanoid.Jump = true human.Health = human.Health - Damage end end script.Parent.Touched:connect(onTouch)
ANY help is appreciated (Videos and Wiki links too) Thanks.
To use debounce, you would need a variable. We could call this variable debounce
.
local debounce = false --Notice how this is a boolean value. It doesn't have to be a boolean. Booleans are simple and easy to use. local debounce_2 = 0 --This is a number value. This would also work if used correctly.
How do they work? Well an If statement checks to see if the debounce is a certain value.
if not debounce then print("Foo") end --Both these will print "Foo". Also, you may want to do "if not debounce" if the debounce is false. As you can see the first debounce example is shorter. if debounce == false then print("Foo") end if debounce_2 == 0 then print("Foo2") end --Both of these also print. if debounce_2 < 1 then print("Foo2") end
Now, denounces are supposed to prevent something from functioning more than once. This is how:
local debounce = false --Now the debounce is false function printme(msg, time) --The message if not debounce then--Do this in anyway of your liking. debounce = true --This will prevent the message from spamming the output. print(msg) --Prints the message wait(time) --Wait time amount of seconds. In this case, it's 3. debounce = false --Turn the debounce to false to be used again. end end while wait() do --loop printme("Foo", 3) --fire the function "printme" with the msg of "Foo" and the time of 3 seconds. end
Now about every 3.03 seconds you will get the message "Foo" in the output.
We can now add this to your script.
local debounce = false --You May make Debounce anything. local Damage = 10 function onTouch(hit) human = hit.Parent:FindFirstChild("Humanoid") if not debounce and human ~=nil and human.Parent.color~=nil then Debounce = true human.Jump = true --The variable human is the humanoid. human.Health = human.Health:TakeDamage(Damage) wait(3)--Wait 3 seconds. debounce = false --Resets debounce. end end script.Parent.Touched:connect(onTouch)
Now in this script, this uses some function called :TakeDamage()
. This might work better because this means that the player can't take damage if it has a ForceField. If you don't want this to happen, just replace line 7 with human.Health = human.Health-Damage
This is how your script will look like:
Debounce = false --You May make Debounce anything. Damage = 10 function onTouch(hit) human = hit.Parent:FindFirstChild("Humanoid") if Debounce == false then Debounce = true if human ~=nil and human.Parent.color~=nil then script.Parent.Parent.Humanoid.Jump = true human.Health = human.Health - Damage wait(1) Debounce = false end end script.Parent.Touched:connect(onTouch)
Look at this webpage: http://wiki.roblox.com/index.php?title=Debounce