How do I make a spark effect?

What do you want to achieve?
I want to make an effect that makes sparks come out of a part in either all directions or just one and the sparks are affected by gravity.


Something like that ^

What is the issue?
I can’t figure out how to, I can’t find any tutorials on how to achieve this but I have seen it used in games.

What solutions have you tried so far?

I have tried using a trail with both attachments on the same part but slightly offset but this wouldn’t work because it would always form a straight line from where the spark started falling when testing. I have also tried using beams but they don’t work either.

I’m guessing that the best way to make this would be to mark the trajectory of lots of tiny parts that come from the big part, this way the sparks would also be affected by gravity and I can know if they touch a player and inflict damage easily.

But how can I mark the trajectory reliably? I’m not aware of any effects made for this purpose, please help.

8 Likes


If you are looking for ParticleEmitters like electric sparks then you have to make your own; you can still use the ParticleEmitter Instance but it won’t look realistic and won’t have collisions.


So I made this module couple minutes ago for this purpose.

local Debris = game:GetService("Debris")
local module = {}
module.particleType = {
	electricSparks = 0
}
function module:emit(particleType, cframe, velocity, rate, size, lifetime, collideable)
	if particleType == 0 then
		for i = rate, 0, -1 do
			local part = Instance.new("Part")
			local trail = Instance.new("Trail")
			local trace0 = Instance.new("Attachment", workspace.Terrain)
			local trace1 = Instance.new("Attachment", workspace.Terrain)
			part.Anchored = false
			part.CanCollide = collideable
			part.CastShadow = false
			part.Locked = true
			part.Massless = true
			part.Transparency = 1
			part.Size = Vector3.new(0.1, 0.1, 0.1)
			part.CFrame = cframe + Vector3.new(math.random(0, 1) * size, part.Size.Y / 2, math.random(0, 1) * size)
			part.Parent = workspace
			trace0.Parent = part
			trace1.Parent = part
			trace0.Position -= Vector3.new(1, 1, 1) * size
			trace1.Position += Vector3.new(1, 1, 1) * size
			trail.Color = ColorSequence.new(Color3.fromRGB(228, 255, 187), Color3.fromRGB(234, 255, 194))
			trail.Transparency = NumberSequence.new(0)
			trail.WidthScale = NumberSequence.new(size)
			trail.FaceCamera = true
			trail.Lifetime = NumberSequence.new(lifetime)
			trail.LightEmission = 1
			trail.LightInfluence = 1
			trail.Attachment0 = trace0
			trail.Attachment1 = trace1
			trail.Parent = part
			part.Velocity = Vector3.new(math.random(-velocity, velocity), velocity, math.random(-velocity, velocity)) -- TODO: Replace .Velocity with the new method because this is going to be deprecated!
			Debris:AddItem(part, lifetime)
		end
	end
end
return module

Then you can use LocalScript to use it. Feel free to add more properties and types of particles.

local ParticleEmitter = require(script.ParticleEmitter)
while wait(0.5) do
	ParticleEmitter:emit(ParticleEmitter.particleType.electricSparks, workspace.Part.CFrame, 100, 100, 0.1, 3, true)
end

If you want to see it yourself, you can download this example that I made: CustomParticleEmitterExample.rbxl (22.7 KB)

You can also play with the LightInfluence property to make the sparks more shiny.

34 Likes

Put the following on top of the script (make sure the ParticleEmitter module is parented to the script)

local ParticleEmitter = require(script.ParticleEmitter)

and then you want to put this

ParticleEmitter:emit(ParticleEmitter.particleType.electricSparks, workspace.Part.CFrame, 100, 100, 0.1, 3, true)

in some function which is called on raycast hit. Here is also what each argument of the function is for…

ParticleEmitter:emit((TypeOfParticle <ParticleType>), (SpawnAt <CFrame>), (Velocity <Number>), (Rate <Number), (Size <Number>), (LifeTime <Number>), (CanCollide <Boolean>)

Can you explain how to change the properties in the script, e.g. The rate, velocity and Cframe?

ParticleEmitter:emit((TypeOfParticle <ParticleType>), (SpawnAt <CFrame>), (Velocity <Number>), (Rate <Number), (Size <Number>), (LifeTime <Number>), (CanCollide <Boolean>)
1 Like

Got it, thank you for the information.

sorry for the bump, but how would i change the direction of the sparks?
I want the sparks to fly how in a cone and not in a circle, how would i do that?

Play with the velocity, it determines in what direction the sparks will go.