ParticleEmitter doesn't enable

  1. What do you want to achieve? I wanna set the “MuzzleFlash” (ParticleEmitter) Enable to true when the tower fires

  2. What is the issue? It doesn’t set enabled to true when the tower fires

  3. What solutions have you tried so far? None

This is the script (also target is the enemy that tower fires at)

local function fireProjectile(tower, target)
	local firePart = tower:FindFirstChild("FirePart")
	local muzzleFlash = firePart:FindFirstChild("MuzzleFlash")
	if firePart and muzzleFlash then
		firePart.MuzzleFlash.Enabled = true
		task.wait(1)
		firePart.MuzzleFlash.Enabled = false
		
	end
end

(tell me if this is wrong category)

1 Like

Its most likely that either firePart or muzzleFlash doesnt exist, try printing each before the if statement to be sure they exist, this is the most basic testing you can do

local function fireProjectile(tower, target)
	local firePart = tower:FindFirstChild("FirePart")
	local muzzleFlash = firePart:FindFirstChild("MuzzleFlash")
    print(firePart, muzzleFlash)
	if firePart and muzzleFlash then
		firePart.MuzzleFlash.Enabled = true
		task.wait(1)
		firePart.MuzzleFlash.Enabled = false
		
	end
end

It exists, it didn’t print anything i don’t know why because i have no errors in output

Are you sure youre calling

fireProjectile(tower, target)

Somewhere in your code?

Double check to see if that function is able to fire at all.

Add prints in places you think might be at fault, like before and after the function and around it.

Click the prints in order from top to bottom and find out exactly where your code is failing

2 Likes

As @smashman65 said, prints are great for troubleshooting. How are you setting tower? Is it from a model in ReplicatedStorage, or cloned version of that model in the workspace?

local function fireProjectile(tower, target)
    print("fireProjectile function called on ", tower.Name, " and ", target.Name)
	local firePart = tower:FindFirstChild("FirePart")
	local muzzleFlash = firePart:FindFirstChild("MuzzleFlash")

	if firePart and muzzleFlash then
		firePart.MuzzleFlash.Enabled = true
		task.wait(1)
		firePart.MuzzleFlash.Enabled = false		
	end
end

Also, how fast is your ParticleEmitter emitting particles? You could test by increasing or decreasing the properties. If the Particle is emitting at a rate of 0 then you won’t see any particles.
Try testing the game and going into the tower and manually setting it to Enabled to see what the emitter looks like when its enabled.

Well, i called fireProjectile(tower, target) somewhere on my code recently i forgot to do that, now @smashman65 print works but the ParticleEmitter still doesn’t enable, the tower is basically like a tower defense game, it comes from ReplicatedStorage and when placed it goes into a folder in workspace named “Towers” also tower it’s a model, the rate of the ParticleEmitter is 15 and the ParticleEmitter when i set it manually to enabled it’s visible

But my question is where is the script referring to the tower model? Is it referencing the tower that’s the original in ReplicatedStorage and not the one in the workspace? Find out where you called fireProjectile(tower, target) and see what tower it’s actually referencing.

You may be getting the prints if you are successfully referring to the incorrect tower, but if you aren’t enabling the proper ParticleEmitter in the workspace then it won’t work.

1 Like

Don’t enable and disable particle emitters rapidly.
Use the :Emit() method, pass a number as an argument (amt of particles to emit)

Hope this helped! :smile:

2 Likes

Don’t worry i already fixed it, but thanks for trying to help, the problem was that the fire part was going into the sky which made me think it didn’t enable

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.