I’m trying to make an attack that’s a simple punch, for simplicity and my sanities sake it uses .Touched with a hitbox. Simple right? But when TakeDamage fires on touch, it damages multiple times, my damage function isn’t the issue here, it works fine when fired on it’s own and I can’t pinpoint the cause of this.
Video of said problem happening.
functions.hitreg = function(player, damage, hitboxduration, force)
-- create hitbox --
local hitbox = script.objects.m1hb:Clone()
hitbox.Parent = player.Character
hitbox.CFrame = player.Character.HumanoidRootPart.CFrame * CFrame.new(0,0,-2)
-- weld it --
local weld = Instance.new("ManualWeld")
weld.Part0 = hitbox
weld.Part1 = player.Character.HumanoidRootPart
weld.C0 = weld.Part0.CFrame:ToObjectSpace(weld.Part1.CFrame)
weld.Parent = weld.Part0
-- touched event --
hitbox.Touched:Connect(function(hitpart)
if hitpart:IsA("BasePart") then
if not hitpart:IsDescendantOf(player.Character) then
local enemy = hitpart.Parent
local ehumanoid = enemy:FindFirstChild("Humanoid")
local ehumanoidroot = enemy:FindFirstChild("HumanoidRootPart")
if enemy and ehumanoid and ehumanoidroot then
game.Debris:AddItem(hitbox, 0.01)
fx.hitsound(ehumanoidroot, "punchhit")
local bv = Instance.new("BodyVelocity")
functions.damage(enemy, damage)
bv.MaxForce = Vector3.new(100000, 100000, 100000)
bv.P = math.huge
bv.Velocity = player.Character.HumanoidRootPart.CFrame.LookVector * force
bv.Parent = ehumanoidroot
game.Debris:AddItem(bv, 0.25)
end
end
game.Debris:AddItem(hitbox, hitboxduration)
end
end)
end