Not possible to delete lightningmodule bolts?

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)
2 Likes

So what you’re saying is that this part doesn’t work?

coroutine.resume(coroutine.create(function()
				wait(debris)
				table.remove(bolts, 1):Destroy();
				NewBolt:Destroy()
			end))
1 Like

The bolts don’t remove, so i’m guessing so.

Could you put a print() inside to see if it’s running?

1 Like

image
It prints, but I think the loop was never broken because it kept printing.

Here’s what the arguments are for server:

	game.ReplicatedStorage.Effect:FireAllClients(2, part1, part2, a1, a2, .5)
	print(game.ReplicatedStorage.Effect)
	wait(3)

I’m not really sure why in the script you try to destroy the same instance twice, but either way if it’s printing then something is being destroyed. Are you printing before or after the instance is destroyed?

edit: Do this:

coroutine.resume(coroutine.create(function()
				wait(debris)
				NewBolt:Destroy()
			end))

In all honesty I’m not sure what the purpose of the table is anyway if you’re not even going to reference it when you destroy the instance.

1 Like

Printing before the instance is destroyed, printing after gives me same thing…