I have a ServerScript inside of a part. This script should access a part in ReplicatedStorage which contains four ParticleEmitters. It should clone this part and place it inside the player’s character. All of this works fine. The issue is that the :Emit() function will not run unless I have a task.wait(0.1) in the script. If I remove the task.wait(0.1), Emit() does not work. How can I fix this? I need to remove the task.wait() because there can’t be a delay.
local barrierVFXClone = barrierVFX:Clone() -- // A part containing 4 particleEmitters and a WeldConstraint
barrierVFXClone.WeldConstraint.Part0 = barrierVFXClone
barrierVFXClone.WeldConstraint.Part1 = character:WaitForChild("HumanoidRootPart")
barrierVFXClone.Position = character.HumanoidRootPart.Position + Vector3.new(0,0,-1.5)
barrierVFXClone.Parent = character
task.wait(0.1) -- // Will not work without this line. I need this line removed though..
for _, child in barrierVFXClone:GetDescendants() do
if child:IsA("ParticleEmitter") then
child:Emit(child:GetAttribute("EmitCount"))
end
end
The best solution to a problem might be the easiest one.
You can wrap this code to a function:
local function emitParticlesForObject(object)
for _, child in object:GetDescendants() do
if child:IsA("ParticleEmitter") then
child:Emit(child:GetAttribute("EmitCount"))
end
end
end
-- // barrierVFXClone stuff.
task.delay(0.1, emitParticlesForObject, barrierVFXClone)
-- // 0.1 is how long the function should wait to be executed. This does not stop the whole script though.
This simply executes the function while not yielding the whole script.
I’m not sure about task.defer() however. Maybe you could use that?
That would work, however I need there to be zero delay in the emission of the particles. The particles should be emitted instantly, there can’t be any delay whatsoever
I’ve looked at other Developer Forums, and it seems that most of the solutions include a wait() function before using ParticleEmitter:Emit(). So, as far as I know, a delay is required to emit the particles, but it not noticeable in someone’s screen.
AFAIK (which isn’t very far) nothing should prevent you from Emitting a ParticleEmitter.
Do you have any idea as to what the problem could be? How long does the delay even need to be for it to work?
Here’s a theory: the ParticleEmitter could be disabled when you call Emit. By adding a delay, you give some other script enough time to enable it back again.