So what I mean is that when my NPC touches a player, it will deal damage. But what my script does is make the NPC deal 5 damage repeatedly since a player is constantly touching the hitbox of the NPC. How would you fix this to make the NPC deal 5 damage every second?
npc = script.Parent
local human = npc:WaitForChild("NPC") --different humanoid name so npcs dont kill each other
local hitbox = npc:WaitForChild("HitBox") --welded a hitbox
hitbox.Touched:connect(function(hit)
local hum = hit.Parent:FindFirstChild("Humanoid")
if hum then
local swing1 = human:LoadAnimation(script.Swing1)
local swing2 = human:LoadAnimation(script.Swing2)
local choose = math.random(1,2)
if choose == 1 then
swing1:Play()
elseif choose == 2 then
swing2:Play()
end
hum:TakeDamage(5)
end
end
end)

1 comment
Do you mean it continuously deals damage after they touch the NPC and walk away or do you mean the NPC can only deal damage after 1 second has passed?