so i have an animation with animationevents.
local function spawnHitbox(hitbox, damage, partToFind, character, partCFrame, animation, sound)
local animator = character.Humanoid.Animator
-- stop animations
for _, track in pairs(animator:GetPlayingAnimationTracks()) do
track:Stop(0.10)
end
animation:Play(0.15)
--print(hitbox, character)
local hrp = character:WaitForChild("HumanoidRootPart")
local connections = {}
for i, connection in connections do
connection:Disconnect()
end
table.clear(connections)
table.insert(connections, animation:GetMarkerReachedSignal("Hit"):Connect(function(player, attack)
print("ae")
local newSound = sound:Clone()
newSound:Play()
local newHitBox = hitbox:Clone()
newHitBox.Parent = game.Workspace
newHitBox.CFrame = partCFrame
newSound.Parent = hrp
local hits = workspace:GetPartsInPart(newHitBox:FindFirstChild(partToFind))
local charactersFound = {}
for i, v in pairs(hits) do
if v.Parent:IsA("Model") and v.Parent:FindFirstChildWhichIsA("Humanoid") and v.Parent ~= character then
if not table.find(charactersFound, v.Parent) then
table.insert(charactersFound, v.Parent)
end
end
end
for i, v in pairs(charactersFound) do
v.Humanoid:TakeDamage(damage)
end
newHitBox:Destroy()
end))
end
i tried using a connections table but “ae” is still being printed multiple times and creates inconsistent damage!
the slash attack is supposed to do 10 damage but it causes more damage each hit. why is this happening and how do i fix it?