How would I make a lightning projectile move from A to B?

They did exactly what you described, but with yields and the tween service. Make the lightning, tween the part’s transparency in order, then tween the transparency back to 1. CFrames are used to reposition parts, though they didn’t do that in the video.

A simple/easier way to make lightning similar to this:

  • Step 1: Get the CFrame you want the lightning to go
  • Step 2: Get the segments, create a table (use the CFrame.Position and the lerp function to the endPosition (do CFrame.Position:lerp(endPosition, [0-1])))
  • Step 3: Loop through the table, add a delay in the loop, each iteration do this: Get and angle (math.random() * math.pi * 2), Add lightningOffsetDistance * cos(angle) * CFrame.RightVector and lightningOffsetDistance * sin(angle) * CFrame.UpVector (note you can also slightning randomize the lightningOffsetDistance), create a part (with transparency 1) from the last point to the current point (add this part to a table for later), create and play a tween to make the part visible
  • Step 4: Once that loop finishes, loop through the list of parts we made earlier and create tweens for each of them to make them invisible (use either Tween.Completed:Wait() or wait()/RunService.Heartbeat:Wait() to yield)
  • Step 5: Clean up. Destroy the parts and tweens.

Note there are tons of things you could do to improve this. A simple one is to vary the lightningOffsetDistance based on the distance from the start and end positions (hint: use the lerp alpha then do 1 - math.abs(alpha - 0.5)*2 (returns 0-1, 0 should have the shortest offset, 1 should have the longest)). You could also do what it looked like the video was doing, where they just did a random spherical offset on all axes, instead of just on two like my example.


If you’re stumped, here are some modules people have made that you might find helpful:

1 Like