How to stop humanoid from taking damage once they have been hit

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)
2 Likes

I am looking at your script and realize you never set Debounce to true.

I can’t use a debounce read the description again

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.

How exactly would I do that? I’m not sure how to use tags

You can create a table, and when it touches the player it checks if a player is in a table, if not add them to the table and damage them.

But then if I do the ability again it wouldn’t work

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.

Hopefully that all makes sense.

3 Likes

I commented out the owner part because I was testing this in studio. You should undo the comment.

1 Like