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
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)