My Touched script won't work for a certain part

So i have been trying to make a script where if a tool touches a ParticleEmitter it will cause an explosion. The explosion part works but i only want it to make an explosion for when it touches the particle emitter. Before i say more, here is the script:

script.Parent.Touched:Connect(function(hit)
	if hit:FindFirstChild("ParticleEmitter") then
		script.Parent.Sound:Play()
		local explosion = Instance.new("Explosion")
		explosion.BlastRadius = 0
		explosion.BlastPressure = 0
		explosion.DestroyJointRadiusPercent = 0
		explosion.Position = script.Parent.Position
		explosion.Parent = game.Workspace
	end
end)

It is rather frustrating as I have also tried a script like this:

function onTouched(part)
	if part.Name == "ParticleEmitter" then
		script.Parent.Sound:Play()
		local explosion = Instance.new("Explosion")
		explosion.BlastRadius = 0
		explosion.BlastPressure = 0
		explosion.DestroyJointRadiusPercent = 0
		explosion.Position = script.Parent.Position
		explosion.Parent = game.Workspace
	end
end
script.Parent.Touched:connect(onTouched)

Neither of them have worked however the second script caused the explosion for every time it was touched, wether it was a ParticleEmitter or not.

I’m not asking for a new script but any help would be appreciated! If you want any more info i’ll happily give more.

did the script error ? since c of connect is in lowercase

also the first script checks if a child of hit is particleemittter, while the second one checks if hit is particleemitter

Do you have the CanTouch Property unchecked (false) for that Part?

Is the Part named ParticleEmitter, or is there a ParticleEmitter in the Part. A ParticleEmitter isn’t a physical object in the workspace.

You should also have a Debounce with a cooldown in the script since when a Player touches a Part the script is fired multiple times.

I think the ‘hit’ is the problem here, try using instead:

if hit.Parent:FindFirstChild("ParticleEmitter") then

Edit: I forgot to say, I’m talking about the first script :sweat_smile:

Sorry it’s just a spelling error, it’s got a capital on the script.

No im sorry it didn’t work. Still the same issue of nothing happening.
i don’t know if it’s something with the tool or what!

try doing some debugging, in the second script put

print(part)

after it checks if the name is “particleemitter”

The CanTouch is True and i just changed the script to BunsenFire - it was not called ParticleEmmiter but it still did not work.

I only didn’t use it because it did the script no matter what part it was - i will still try it if you think it can fix the problem?

it wont fix the problem, but it will help find the cause of it

It did work, anything else you can add on to that?

Hey, I think I found the issue within’ your code.

By using Instance:FindFirstChild(string) you are actually looking for an instance with that name, but if you use Instance:FindFirstChildWhichIsA(class) instead, it’ll look for an instance which ClassName’s matches that.

script.Parent.Touched:Connect(function(hit)
	if hit and hit:FindFirstChildWhichIsA("ParticleEmitter") then
		local particle = hit:FindFirstChildWhichIsA("ParticleEmitter")
		particle:Destroy()
		local explosion = Instance.new("Explosion")
		explosion.BlastRadius = 0
		explosion.BlastPressure = 0
		explosion.DestroyJointRadiusPercent = 0
		explosion.Position = script.Parent.Position
		explosion.Parent = workspace
	end
end)

Also, I don’t know if your intention was deleting the emitter post collision, but on the code I wrote I’ve implemented that already!

Oh, and to add up onto this:
Incase you do not want a part to lose it’s particle emitter but also don’t want it to be triggered again you can use a dictionary to achieve something like a Blacklist.

local blacklist={}
script.Parent.Touched:Connect(function(hit)
	if hit and not blacklist[hit] and hit:FindFirstChildWhichIsA("ParticleEmitter") then
		--The "not blacklist[hit]" is just to check if the part you are touching isn't already in the blacklist.
		blacklist[hit]=true --This adds the part into the blacklist, so if you ever collide on the part again utilizing the tool, it won't trigger it again. (Unless the script is resetted)
		local explosion = Instance.new("Explosion")
		explosion.BlastRadius = 0
		explosion.BlastPressure = 0
		explosion.DestroyJointRadiusPercent = 0
		explosion.Position = script.Parent.Position
		explosion.Parent = workspace
	end
end)

Thank you all for the help but I managed figured it out myself!

I changed the script to this format:

local Value1 = 0
script.Parent.Touched:Connect(function(touch)
	if touch.Name == "CopperOxideZone" and Value1 == 0 then
		wait(1)
		script.Parent.Sound:Play()
		local explosion = Instance.new("Explosion")
		explosion.BlastRadius = 0
		explosion.BlastPressure = 0
		explosion.DestroyJointRadiusPercent = 0
		explosion.Position = script.Parent.Position
		explosion.Parent = game.Workspace
		Value1 = 1
		touch.Parent.Union.Transparency = 1
		touch.Anchored = false
	end
end)

The script is now in the particle emitter so i believe it was the script being in a tool that caused the problem. I may be wrong as i did change the script format but it does work now!

Thank you everybody for helping me on my first post, i hope you all have a great day!