ParticleEmitter:Emit() doesn't emit at the very first time, but emits normally after that

As the title says, the particleEmitter effects I have for my ability doesn’t seem to emit at the very first ability usage, but for the rest usages after that it works normally. I tried adding wait() before emit() but still doesnt work. Below is how I clone and emit particle in client on ability trigger:

-- In VFX Local script
local BlinkFX_new = VFX.PostBlinkVFX:Clone()
	BlinkFX_new.Position = newPos
	BlinkFX_new.Parent = workspace.Fx
	for _, particle in pairs(BlinkFX_new:GetDescendants()) do
		if particle:IsA("ParticleEmitter") then
			wait()
			particle:Emit(particle:GetAttribute("EmitCount"))	
		end
	end
	Debris:AddItem(BlinkFX_new, 3)
2 Likes


Forgot to upload vdo, here it is, u can see that on the first blink the FXs doesnt emit, but on the second blink(and the rest after this) it does emit

1 Like

Use ipairs instead of pairs for the for loop. Pairs should be used for tables and ipairs for instances

1 Like

Thanks, didnt solve the prob tho

1 Like

I believe it might just be that its not retrieving the emitCount Attribute right, so just ensure that it is set right. I made a slightly better version with a fallback value -

for _, particle in ipairs(BlinkFX_new:GetDescendants()) do
	if particle:IsA("ParticleEmitter") then
		local emitCount = particle:GetAttribute("EmitCount") or 5 -- fallback value
		particle:Emit(emitCount)
	end
end
1 Like

pairs arent needed…

4 Likes

Was gonna say this but never did my research enough to tell that pairs & ipairs are deprecated, either way it’s not like using ipairs is gonna make the instances magically appear lol.

1 Like

Yeah that’s my bad, I thought there was something going for ipairs.

1 Like

hmm it probably has to do with loading the effects and all; I’d say try to run some debugging and tell us the results:

  • add a longer wait (maybe a second or so) before the for loop, just to let it load properly
  • after you do the ability for the first time, wait another like 5 seconds then do it again and check if the issue happens again
2 Likes

So I can just do this instead?

for k, v in table do
...
end
1 Like

Didnt work, but thanks for the fallback value comment tho, didnt have that at first but added that in now just in case

1 Like

Ok I tried adding wait(5) before emit and it works, seems like the problem is it is not cloned fast enough. But I dont think adding a wait time before emit is a good solution because that introduces some noticable delay. Are there any other solutions? Should I pre-clone every FXs when character loads in and then move and activate it when needed etc…?

1 Like

yes.

1 Like

Okayy so we found the problem
I recommend cloning and debris:AddItem() in the Server and then sending the particles to the client to emit them. Kinda like that:

Server

...
	local BlinkFX = VFX.PostBlinkVFX:Clone()
	BlinkFX.Position = newPos
	BlinkFX.Parent = workspace.Fx
	
	remoteEvent:FireAllClients(blinkFX)
	
	debris:AddItem(BlinkFX, 3)

Client



remoteEvent.OnClientEvent:Connect(function(vfx)
	for _, particle in pairs(vfx:GetDescendants()) do
		if particle:IsA("ParticleEmitter") then
			particle:Emit(particle:GetAttribute("EmitCount"))	
		end
	end
end)

Try putting a RunService.Heartbeat:Wait() in the loop. I think this happened to me before and that fixed it.

For the caster player i planned to emit locally on his client as soon as he presses the ability key for the instant feel, if i clone in server and send to client to emit, even the caster will feel a slight delay which i want to prevent. Any solution?

unfortunately it didnt work for me

I recommend you emit the particles instantly in the ability then instead of FireAllClients() do:

for i,v in pairs(game.Players:GetPlayers()) do
	if v ~= PLAYER_WHO_USED_THE_ABILITY then
		remoteEvent:FireClient(v, blinkFX)
	end
end

The Effects should be replicating to all clients to begin with, no need for the server to be creating assets.

If the user just sets up Networking events for Client & Server on the attacks it should work like a charm and be super smooth, with the server controlling, of course, server properties.

No matter what i try the problem still persist, and upon further testing it seems that it is random, where sometimes it does work the first go but sometimes it just doesnt, as seen in this vid. Maybe this is just a bug in the studio? i just hope this doesnt happen in live game. I even tried ObjectPooling, using PreloadAsync() etc… nothing works, it is just completely random