My touched script ignores my if statement

So before i go into detail, here is the script:

script.Parent.Touched:Connect(function(hit)
	if hit:FindFirstChild("ParticleEmitter") or ("Nozzle") then
		script.Parent.Fire.Enabled = false
	end
end)

Now the issue is it ignores the if statement and will turn off the fire if it touches anything. What i would like the script to do is turn of the fire when it is touched by a ParticleEmitter but i am having toubles.

I don’t understand what i am doing wrong as i beleive i have done everything correct so any help will be appreciated! Yes i know this is only a small simple post which also means i hope for a small simple answer but yet again, any help is highly appreciated! - NathanPlays2016

It’s because of the or Nozzle part, you’re checking if a string is truthy there, which it almost always is

You have to give something to compare with nozzle, if you’re checking if the name is Nozzle, then you have to compare the name of “hit” with Nozzle or what you were planning on doing

if hit:FindFirstChild("ParticleEmitter") or hit.Name == "Nozzle" then

I have changed the script to your layout but there is a new issue. The part now does not detect when anything touches it. Here is the new script:

script.Parent.Touched:Connect(function(hit)
	if hit:FindFirstChild("ParticleEmitter") or hit.Name == "Nozzle" then
		script.Parent.Fire.Enabled = false
	end
end)

I also have some images to show what i mean:
image
image

Any new help is appreciated!

Maybe it could be how your hose works? Can you try to rename one your legs to Nozzle using the explorer during testing/inserting a ParticleEmitter to ensure the if statement is working correctly?

I don’t under stand this quite right

hit:FindFirstChild("ParticleEmitter") 

what would be hit exactly? is it a transparent part? can you use some print statements too like

script.Parent.Touched:Connect(function(hit)
        if hit.Name == "Nozzle" then
                print("found emmiter")
		script.Parent.Fire.Enabled = false
	end
	if hit:FindFirstChild("ParticleEmitter") then
                print("found emmiter")
		script.Parent.Fire.Enabled = false
	end
end)

No hit is the function. I don’t know how to describe it really but it is what part touches the fire block.

ik how hit works but what is hit if the if statement goes true? are you trying too see if it touches a particle?

I just did, no difference the fire stayed on.

Just to be clear, you did what I said server side right?

Can we see the code that makes the hose work, the problem could be there

1 Like

A string is always truthy in Lua, even an empty string "".

print("" and true) --true

if hit:FindFirstChild("ParticleEmitter") or hit:FindFirstChild("Nozzle") then