Anyone know how i make a dmg when u touch a part, with cooldown
When i do it whitout cooldown the player die
You can use a debounce
.
Example:
local debounce = false -- set it to false on default so that it doesn't interfere with the script.
script.Parent.Touched:Connect(function(hit)
if hit.Parent:FindFirstChildOfClass("Humanoid") then
hit.Parent:FindFirstChildOfClass("Humanoid"):TakeDamage(20) -- You can change the dmg value if you'd like.
end
end
That script auto kill me, too.
Try this:
local debounce = true
script.Parent.Touched:Connect(function(hit)
local Humanoid = hit.Parent:FindFirstChildOfClass("Humanoid")
if Humanoid and debounce then
debounce = false
Humanoid.Health = Humanoid.Health - 20 -- So you can take damage with forcefeild on
wait(1) -- How Long in between hits
debounce = true
end
end)
1 Like
:TakeDamage() will only do damage if force field is off.
My bad, forgot to actually use the debounce
local debounce = false -- set it to false on default so that it doesn't interfere with the script.
script.Parent.Touched:Connect(function(hit)
if not debounce then
debounce = true
if hit.Parent:FindFirstChildOfClass("Humanoid") then
hit.Parent:FindFirstChildOfClass("Humanoid"):TakeDamage(20) -- You can change the dmg value if you'd like.
task.wait(1)
debounce = false
end
end
end
2 Likes