Particles being weird clientside. Is there a fix?

Hi guys. My particles in my addon have been acting strangely which is probably an error on my part. Please excuse all of the IF CLIENT and IF SERVER’s everywhere in my code. It’s the only way I could get what I wanted to be server and client side. My problem is that when I have ParticleEffectAttach serverside and I’m in single player, the particles act normally. I use them as trails. Although in multiplayer, they don’t work. I solved this problem by making ParticleEffectAttach clientside, but this created another problem. When the particles spawn, it’s a shitstorm of the trails. Instead of being just one particle spawning on the player. It appears to be multiple particles.



function SWEP:AddLightning()
	local vel = self.Owner:GetVelocity():Length()
	local lightning_min = 1500

	if vel > lightning_min then
		if self:GetNWBool("TFS_CanPlayLightning",false) and self.Owner:GetNWBool("TFS_Speedster",false) and not self.Owner:GetNWBool("TFS_V9",false) then
			if CLIENT then
				ParticleEffectAttach(self.Owner:GetNWString("TFS_LightningEffect","yellow_lightning"),PATTACH_POINT_FOLLOW, self.Owner ,0)
			end
			if SERVER then
				self:SetNWBool("TFS_CanPlayLightning",false)
			end
		elseif self:GetNWBool("TFS_CanPlayLightning",false) and self.Owner:GetNWBool("TFS_Speedster",false) and self.Owner:GetNWBool("TFS_V9",false) then
			if CLIENT then
				ParticleEffectAttach("v9_lightning",PATTACH_POINT_FOLLOW, self.Owner ,0)
			end
			if SERVER then
				self:SetNWBool("TFS_CanPlayLightning",false)
			end
		end
	else
		if SERVER then
			self:SetNWBool("TFS_CanPlayLightning",true)
		end
		self.Owner:StopParticles()
	end
end


Well obviously your code clientside is being executed multiple times, probably due to prediction.

I can go through the logic of the code. What do you mean prediction? Is there something you can suggest I do?