Debounce not working

Hey there! For some reason my debounce isn’t working. How would I fix the script?
script:

local isTouched = false
	
	Snowball.Touched:Connect(function(hit)
		if hit.Parent.Name == "Big elf" or hit.Parent.Name == "Santa claus" and isTouched == false then
			isTouched = true
			hit.Parent.Humanoid:TakeDamage(DamageValuee)
			Snowball:Destroy()
			if hit.Parent.Humanoid.Health <= 0 then
				plr.leaderstats["Elfs defeated"].Value = plr.leaderstats["Elfs defeated"].Value + 1
			end
			wait(1)
			isTouched = false
		end
	end)

Any help is appreciated!

3 Likes

I think the issue is your logic statement, try prioritizing conditions:

local name = hit.Parent.Name
if (name == "Big elf" or name == "Santa claus") and not isTouched then
	--your code
end
5 Likes

It works, thanks! But what is the difference between what I used and what you used?

2 Likes

The or in the if statement makes the difference. It separates the statement and check if one of them is valid. So either the name is big elf or the name is santa Claus and the denounce is false. So when the name is big elf it completely ignores the rest of the statement (also the debounce)

The solution from nyrion now checks if the name is big elf and denounce is false or the name is santa Claus and the denounce is false

if (name == "Big elf" or name == "Santa claus") and not isTouched then

is basicly the same as the code beloojust without the brackets

if name == "Santa claus" and not isTouched or name== "Big elf" and not isTouched then

explaining sucks lol so I hope you understand my explanation

3 Likes

Alright, thanks! (don’t worry you’re good at explaining stuff)

3 Likes