I'm making a weapon that, when it hits an object with a humanoid in it, will deal a set amount of damage. The weapon treats the "hitbox" on it as always being active and in the Output, will show that it has hit many times, up to thousands of times in a second. Is there a way to fix this?
TL;DR: I'm trying to fix the collisions on my weapon so that it doesn't instakill whatever it touches.
Here is my code.
local function onTouched(hit)
if active == false then return end
local human = hit.Parent:findFirstChild("Humanoid")
if (human ~= nil) then
human.Health = human.Health - hurt.Value
print "touching a humanoid"
wait(1)
end
end
local function damage(player,boxactive,aerial,swing1,swing2)
if boxactive == false then
print "box not active"
return end
print "box active"
if aerial == true then
hurt.Value = 10
print ("aerial damage set "..hurt.Value)
elseif swing1 == true then
hurt.Value = 20
print ("swing1 damage set "..hurt.Value)
elseif swing2 == true then
hurt.Value = 15
print ("swing2 damage set "..hurt.Value)
end
while boxactive == true do
active = boxactive
script.Parent.Touched:Connect(onTouched)
wait(1)
end
end
boxActiveEvent.OnServerEvent:Connect(damage)
Thank you in advance.

2 comments
Instead of using human.Health = human.Health - hurt.Value You should use human:TakeDamage.
add a debounce canDamage = true when you hit do canDamage = false wait(idk how long)