Help touch isnt working right

DamageValue = 15

local debounce = false

function onTouch(hit)
if debounce == false then
debounce = true
if hit.Name ~= “Ignoreme” then
hit.Parent.Humanoid.Health = hit.Parent.Humanoid.Health -DamageValue

	elseif hit.Name == "Ignoreme" then
		hit.Parent.Parent.Humanoid.Health = hit.Parent.Parent.Humanoid.Health -DamageValue 
   wait(4)
		debounce = false

	end
end	

end

script.Parent.Touched:connect(onTouch)

1 Like

Move the debounce = true statement here:

What’s happening is that when the if hit.Name ~= "IgnoreMe" condition is true, the debounce variable never goes back to false. You should always have both debounce toggles within the same condition

This isn’t the issue, and also moving the debounce = true to inside the elseif won’t make the debounce return to false if hit.Name ~= “IgnoreMe”` condition is true. The debounce will be properly set up if you move the debounce = false to after the elseif (so between the last two ends).

The issue that the ouput shows is that the humanoid is not a valid member of the unionoperation IgnoreMe.

Can you show the hierarchy of the IgnoreMe union in your explorer?

sorry to go off topic, you can do hit.Parent.Humanoid:TakeDamage(DamageValue) to simplify the code
you could also do hit.Parent.Humanoid.Health -= DamageValue