I've been trying to figure this out for a while but nothing seems to be working can i have help all i want is so when you left click the damage is active for only 3 seconds, this is just so i don't have to worry about somebody running into the blade and dying without me actually attacking them IMPORTANT: the script is in a part called: blade (no caps) (it's the hitbox of the sword essentially)
01 | local debounce = false |
02 | local HealthLoss = 35 -- Damage |
03 | function OnTouched(Part) |
04 | if Part.Parent ~ = nil then |
05 | if debounce = = false and Part.Parent:findFirstChild( "Humanoid" ) ~ = nil then |
06 | debounce = true |
07 | Part.Parent:findFirstChild( "Humanoid" ):TakeDamage(HealthLoss) |
08 | wait( 2 ) |
09 | debounce = false |
10 | end |
11 | end |
12 | end |
13 | script.Parent.Touched:connect(OnTouched) |
Use a variable to define if the tool was activated or not. If it wasn't, the "Touched" event would not execute any further.
Final code:
01 | local tool = --your tool |
02 | local toolActive = false |
03 | local damage = 35 |
04 | local duration = 3 |
05 |
06 | local function onTouched(hit) |
07 | if not toolActive then do return end end |
08 | local Humanoid = hit.Parent:FindFirstChildOfClass( "Humanoid" ) |
09 | if Humanoid then |
10 | Humanoid:TakeDamage(damage) |
11 | end |
12 | end |
13 |
14 | local function onActivated() |
15 | if toolActive then do return end end |
16 | toolActive = true ; wait(duration); toolActive = false |
17 | end |
18 |
19 | script.Parent.Touched:Connect(onTouched) |
20 | tool.Activated:Connect(onActivated) |