Ok so, I'm making some weapons, and there is some zombies, difference between a zombie and a player is that the zombies have an attribute in their humanoid, well, the weapon makes a hitbox by creating a part infront of the player, and checking for touched event to dmg the zombie.
This works perfectly, yet, the touched event fires alot of times as the zombie keeps touching the hitbox.
Using "debounce" wont work, because I want the weapon to be able to damage many zombies at once, just not the same ones.
So my question is:
How do I check if that zombie has already been damaged by the attack?
Here's my code if you need it:
hitbox.Touched:Connect(function(hit) if hit.Parent:FindFirstChild("Humanoid") then if hit.Parent.Humanoid:GetAttributes("IsNPC") then local npc = hit.Parent local hum = npc.Humanoid hum:TakeDamage(35) end end end)
"hitbox" is the part I use as the hitbox.
First dont use touched event to attack write your own ray cast function or use raycastHitbox v4.0 it handles hit for you can can hit multiple enemy
edit: if you somehow cant use RaycastHitbox then you can try this
local Db = nil local Hitbox = script.parent.Hitbox Hitbox.Touched:Connect(function(OtherPart) if Db ~= OtherPart.Parent then Db = OtherPart.Parent wait(1) Db = nil end end)