Slight delay when cloning particles

Hi, my name is Jahanzaib, and I’m making a spellcrafting game. So far, everything works fine, but when I cast the spell, it takes a second for the particles to start showing. Here’s a video showing how it looks:

I don’t know why it happens. I’ve tried everything from preloading to switching from ServerStorage to ReplicatedStorage and to calling ParticleEmitters:Emit() as soon as the fireball is parented to workspace, all to no avail.

Here’s the code handling the Particles:

self.Particles = rs:WaitForChild("Particles")[MagicData.Elements[self.Element].essence].Container or self.Particles
	
	local bases = rs:FindFirstChild("SpellTypes")
	local archetype = bases[self.SpellType]:FindFirstChild(self.SpellType .. tostring(math.random(1, #bases[self.SpellType]:GetChildren()))):Clone()
	
	for i, v in ipairs(self.Particles:GetChildren()) do
		print(v)
		local newParticle = v:Clone()
		if newParticle:FindFirstChildWhichIsA("ParticleEmitter") then
			newParticle:FindFirstChildWhichIsA("ParticleEmitter").Color = ColorSequence.new(self.PrimaryColor)
			print("changed color of ParticleEmitters")
		else
			print("no ParticleEmitters")
		end
		newParticle.Parent = archetype
	end
	if archetype:FindFirstChildWhichIsA("Trail") then
		archetype:FindFirstChildWhichIsA("Trail").Attachment0 = archetype:FindFirstChild("Inner")
		archetype:FindFirstChildWhichIsA("Trail").Attachment1 = archetype:FindFirstChild("TrailAttachment")
		archetype:FindFirstChildWhichIsA("Trail").Color	= ColorSequence.new(self.PrimaryColor)
	else
		print("no trail")
	end

This is in a ModuleScript in ServerScriptService, which is called from a regular Script after a RemoteEvent fires from a LocalScript in StarterGui after the player presses R.
The only other code I used was in the server-side Script:

projectile.Inner.ParticleEmitter:Emit(10)
projectile.Outer.ParticleEmitter:Emit(10)

Any and all help would be appreciated!

Does the animation play when you press R on the Client Side?

Yes, it does. I have two animations: one is a charging animation, the other is the throwing animation. The video shows both of them. The player starts charging by pressing R once, then throws by pressing R again, Everything works, it’s just the particles that show up later.

Do you play the Animations on Client side or server side?

Client side. That’s not really relevant to the particles emitting, though. You can see in the video that the ball spawns, but it takes a while for the particles to load.

That’s probably the reason, try rendering the particles on Client side aswell and tell me the result

I ran into a lot of issues with this (dumb ones) but I got it to work in the end. However, the particles still delay.

I added this to the ModuleScript:

self.Object = archetype

	-- Fire client event for immediate particle visuals
	if self.Owner then
		rs.RenderParticles:FireClient(self.Owner, self.Object.Name, self.Particles, self.PrimaryColor)
	end

I put this into a LocalScript:

game:GetService("ReplicatedStorage").RenderParticles.OnClientEvent:Connect(function(spellName, particlesContainer, color)
	local archetype = workspace.SpellStorage:WaitForChild(spellName)
	if not archetype then return end

	for _, v in ipairs(particlesContainer:GetChildren()) do
		local newParticle = v:Clone()
		local emitter = newParticle:FindFirstChildWhichIsA("ParticleEmitter")
		if emitter then
			emitter.Color = ColorSequence.new(color)
		end
		newParticle.Parent = archetype
	end

	local trail = archetype:FindFirstChildWhichIsA("Trail")
	if trail then
		trail.Attachment0 = archetype:FindFirstChild("Inner")
		trail.Attachment1 = archetype:FindFirstChild("TrailAttachment")
		trail.Color = ColorSequence.new(color)
	end
end)

The delay still happens, though.

1 Like

By the way, when do you fire the Particle Emitter function? After the animation or at the same time as the animation?

I deleted it because I thought it wasn’t doing anything. I was wrong. It worked when I called it from the LocalScript! Thank you!

1 Like

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