today I work a lot on my combat system that I manage to do better and better, but I meet a big problem why its print “a” several times
function playerHit()
local partCollider = colliderArray[newIndex]
local basePart = character:FindFirstChild(partCollider.Hit) :: BasePart
local animation = Instance.new("Animation")
animation.AnimationId = partCollider.AnimationId
if countDownDebounce then
local animationTrack = humanoid:LoadAnimation(animation)
animationTrack:Play()
countDownDebounce = false
if basePart then
basePart.Touched:Connect(function(hit)
if hit.Name == "HumanoidRootPart" and hit ~= humanoidRootPart then
print("a")
end
end)
end
animationTrack.Ended:Connect(function()
countDownDebounce = true
SetNewIndex()
end)
else
return
end
end
mouse.Button1Down:Connect(function()
playerHit()
end)
Touched events are really buggy and don’t have a cooldown or debounce
use a variable to fix this, set it to true or false depending on what you wanna do
local deb = false
if basePart then
basePart.Touched:Connect(function(hit)
if deb then return end
deb = true
if hit.Name == "HumanoidRootPart" and hit ~= humanoidRootPart then
print("a")
end
end)
end
.Touched isn’t only fired by the instance that owns the part, in this case, PartA is owned by client1, but it will still make a .Touched event for PartB, even though it doesn’t own it, and another client is replicating the .Touched event
It works in a weird way… Imo, only the instance owning the part should be able to do a .Touched event for that part