✓ Accepted answer
To use debounce, you would need a variable. We could call this variable debounce.
local debounce = false
local debounce_2 = 0
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
if debounce == false then
print("Foo")
end
if debounce_2 == 0 then
print("Foo2")
end
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
function printme(msg, time)
if not debounce then
debounce = true
print(msg)
wait(time)
debounce = false
end
end
while wait() do
printme("Foo", 3)
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
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
human.Health = human.Health:TakeDamage(Damage)
wait(3)
debounce = false
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
3 comments
Yes, use a debounce. I assume this is just a platform to step or land on. If you don't have a debounce then you'll take damage multiple times. Try to make it maybe a second or so.
Its actually a block attached to an NPC, I dont exactly know how to use debounce yet, could you demonstrate for me?
Yes, this has been happening to me too. I just save the game, close the studio and reopen the studio and saved file. Also, accept this answer please.