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)
local debounce = false local HealthLoss = 35 -- Damage function OnTouched(Part) if Part.Parent ~= nil then if debounce == false and Part.Parent:findFirstChild("Humanoid") ~= nil then debounce = true Part.Parent:findFirstChild("Humanoid"):TakeDamage(HealthLoss) wait(2) debounce = false end end end 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:
local tool = --your tool local toolActive = false local damage = 35 local duration = 3 local function onTouched(hit) if not toolActive then do return end end local Humanoid = hit.Parent:FindFirstChildOfClass("Humanoid") if Humanoid then Humanoid:TakeDamage(damage) end end local function onActivated() if toolActive then do return end end toolActive = true; wait(duration); toolActive = false end script.Parent.Touched:Connect(onTouched) tool.Activated:Connect(onActivated)