Particle Emitter not Emitting

Hey, I am creating a particle emitter script for my game, but when I try to emit it on this function, it simply doesn’t work, but when I try on “Run” mode, it works?

The function i’ve made:

function effect()
	local particle = script.Parent.Parent.effectpart.Attachment.ParticleEmitter
	spawn(function()
		particle.Speed = NumberRange.new(30)
		wait()
		particle:Emit(35)
		wait(2)
		particle.Speed = NumberRange.new(10)
	end)
end

function ifdie(player) -- this function i made when the zombie dies, it does a effect on his part.
	script.Parent.Parent.Humanoid.Died:Connect(function()
		if alreadyifdie == false then
			alreadyifdie = true
			spawn(function()
				wait()
				effect()
			end)
			script.Parent.Parent.effectpart.Anchored = true
		end
	end)
end

The properties:

It’s because your function attaches the event too. Humanoid.Died happens every time a humanoid dies, and you attach something to it every time you call ifdie(). Instead of attaching a new event every time, you’re supposed to do it like such:

function effect()
	local particle = script.Parent.Parent.effectpart.Attachment.ParticleEmitter
	spawn(function()
		particle.Speed = NumberRange.new(30)
		wait()
		particle:Emit(35)
		wait(2)
		particle.Speed = NumberRange.new(10)
	end)
end

function ifdie(player) -- this function i made when the zombie dies, it does a effect on his part.
	if alreadyifdie == false then
		alreadyifdie = true
		spawn(function()
			wait()
			effect()
		end)
		script.Parent.Parent.effectpart.Anchored = true
	end
end

script.Parent.Parent.Humanoid.Died:Connect(ifdie)

Thanks!! It worked now, and the particle emitter emits!

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