every single time i try to make a combat system i run into this problem where touch event just ignores disconnect entirely and i never manage to fix it
but in this case it was different, it keeps doubling the touch events, every swing is like 1,2,4,8,16
heres part of my code
theres more but i put just the essential (yes theres debounce)
H.E.L.P
tool.Activated:Connect(function()
attack_track:Play()
attack_track:GetMarkerReachedSignal("hit"):Connect(function(param)
local hitbox = char:FindFirstChild("Weapon")
local hits = {}
local touch
touch = hitbox.Touched:Connect(function(part)
local echar = part:FindFirstAncestorWhichIsA("Model")
local ehuman = echar:FindFirstChildWhichIsA("Humanoid")
if (echar and echar ~= char) and (ehuman and ehuman.Health > 0) then
if not hits[echar] then
hits[echar] = true
print(echar)
end
end
end)
attack_track:GetMarkerReachedSignal("hitend"):Connect(function()
touch:Disconnect()
end)
end)
end)
Add a print statement to check whether the event is actually firing. Also, I’m pretty sure that you should be using raycasting instead of the .Touched since it’s more accurate.
You should only create the connections once, not every time the tool is activated.
local touch
tool.Activated:Connect(function()
attack_track:Play()
end)
attack_track:GetMarkerReachedSignal("hit"):Connect(function(param)
local hitbox = char:FindFirstChild("Weapon")
local hits = {}
touch = hitbox.Touched:Connect(function(part)
local echar = part:FindFirstAncestorWhichIsA("Model")
local ehuman = echar:FindFirstChildWhichIsA("Humanoid")
if (echar and echar ~= char) and (ehuman and ehuman.Health > 0) then
if not hits[echar] then
hits[echar] = true
print(echar)
end
end
end)
end)
attack_track:GetMarkerReachedSignal("hitend"):Connect(function()
touch:Disconnect()
end)