I am using @Quasiduck’s Lightning Module but I can’t figure out how to delete the bolts after some time. Here’s my code of the lightning bolt.
local LightningSparks = require(game.ReplicatedStorage.LightningBolt.LightningSparks)
local LightningExplosion = require(game.ReplicatedStorage.LightningBolt.LightningExplosion)
local LightningBolt = require(game.ReplicatedStorage.LightningBolt)
local function zap(waittime, part1, part2, a1, a2, debris)
print(60)
local ranCF = CFrame.fromAxisAngle((part2.Position - part1.Position).Unit, 2*math.random()*math.pi)
local A1, A2 = {}, {}
local timeElapsed = 0
local bolts = {}
A1.WorldPosition, A1.WorldAxis = a1.WorldPosition, a1.WorldAxis
A2.WorldPosition, A2.WorldAxis = a2.WorldPosition, a2.WorldAxis
coroutine.resume(coroutine.create(function()
while true do
if timeElapsed == waittime then
break end
local NewBolt = LightningBolt.new(A1, A2, 20)
table.insert(bolts, NewBolt);
NewBolt.PulseSpeed = 2
NewBolt.PulseLength = 0.5
NewBolt.FadeLength = 0.25
NewBolt.Color = Color3.new(math.random(), math.random(), math.random())
--NewBolt.MaxRadius = 1
wait(0.1)
timeElapsed = timeElapsed + 0.1
coroutine.resume(coroutine.create(function()
wait(debris)
table.remove(bolts, 1):Destroy();
NewBolt:Destroy()
end))
end
end))
end
game.ReplicatedStorage.Effect.OnClientEvent:Connect(function(waittime, part1, part2, a1, a2, debris)
zap(waittime, part1, part2, a1, a2, debris)
end)