I have a part named “Blade” in my tool which is acting as a hitbox for my sword. I need the “Blade” to deal damage to the NPC when it is hit. how would i go about doing this?
I am assuming you do not want to use .Touched for these triggers. So I recommend looking into this useful module:
local tool = script.Parent
local blade = tool:WaitForChild("Handle") --change name if necessary
local swingConn
local debounce = false
tool.Activated:Connect(function()
swingConn = blade.Touched:Connect(function(hit)
if debounce then
return
end
local enemyHum = hit.Parent:FindFirstChild("Humanoid")
if enemyHum then
debounce = true
enemyHum:TakeDamage(10) --damage, change damage if necessary
end
task.wait(0.5) --cooldown, change if necessary
debounce = false
end)
end)
tool.Deactivated:Connect(function()
if swingConn then
swingConn:Disconnect()
end
end)
Here’s a damaging script which works when parented to the Tool instance. I’ve added a few comments in areas which might need changing.
1 Like
Thank you! This works perfect.