I want it so that when my ability touches a humanoid it takes damage but once it has it can’t damage the same one again and I can’t do a debounce because then if it hit 2 humanoids only one will take damage. Please help.
Code:
local debounce = false
local cooldown = 0.2
script.Parent.Touched:Connect(function(hit)
local humanoid = hit.Parent:FindFirstChildWhichIsA("Humanoid")
if humanoid then
if script.Parent.Parent.e1:GetAttribute("Owner") == hit.Parent.Name then
humanoid.Health +=0
else
humanoid.Health -= 50
end
end
end)
Instead of using a debouce add a tag to a player who has been hit and see if it if another player touches and see if it exist if not damage them then tag them.
I suggest you use a dynamic debounce approach. In the linear debounce configuration you’re thinking of, the part will not deal damage to any humanoid within a certain time after a humanoid took damage. In a dynamic debounce, the part will not deal damage to only the humanoids that touched it within the time span.
To do this, I suggest a system such as the following:
local humanoidsTouched = {}
local cooldown = 0.2
script.Parent.Touched:Connect(function(hit)
local humanoid = hit.Parent:FindFirstChildWhichIsA("Humanoid")
if humanoid then
if --[[script.Parent.Parent.e1:GetAttribute("Owner") ~= hit.Parent.Name and]] table.find(humanoidsTouched, humanoid) == nil then
table.insert(humanoidsTouched, humanoid)
humanoid.Health -= 50
task.wait(cooldown)
table.remove(humanoidsTouched, table.find(humanoidsTouched, humanoid))
end
end
end)
The humanoidsTouched table stores all of the humanoids touched recently. When a character touches the part, the script will check to see if the character’s humanoid exists in the table, and if it doesn’t (meaning it hadn’t been touched recently), insert the character’s humanoid into the table and after the cooldown time, remove it from the table.