So i want my sword to be "multi-target" but the script finds one humanoid and affects that one ignoring all other humanoids. here's the code :
local weapon = script.Parent local dmg = 20 weapon.Touched:connect(function(part) if part.Parent:FindFirstChild("Humanoid")then if CanDamage.Value == true then -- i hid where CanDamage came from local humanoid = part.Parent:FindFirstChild("Humanoid") humanoid:TakeDamage(dmg) CanDamage.Value = false -- here too end end end)
Thanks in advance
The CanDamage variable, when set to false, stops the part from dealing damage after the first hit. Regardless of how many other humanoids it hits. The solution? Create a table which tracks what humanoids have been hit and stops the function from running if it found them in it.
local humanoidsThatHaveBeenHit = {} weapon.Touched:connect(function(part) if part and part.Parent then local humanoid = part.Parent:FindFirstChild("Humanoid") if humanoid and not humanoidsThatHaveBeenHit[humanoid] then humanoidsThatHaveBeenHit[humanoid] = true humanoid:TakeDamage(20) end end end)
At the end of the attack; maybe once the animation has stopped running. Or however you've coded it you can simply do humanoidsThatHaveBeenHit = {}
.