local P={}P.__index=P local Y={}function P.new(r,n)local S=setmetatable({},P)S.Enabled=true S.LightningBolt=r S.MaxSparkCount=n or 10 S.MinSpeed=4 S.MaxSpeed=6 S.MinDistance=3 S.MaxDistance=6 S.MinPartsPerSpark=8 S.MaxPartsPerSpark=10 S.SparksN=0 S.SlotTable={}S.RefIndex=#Y+1 Y[S.RefIndex]=S return S end function P.Destroy(P)Y[P.RefIndex]=nil for Y,r in pairs(P.SlotTable)do if r.Parts[1].Parent==nil then P.SlotTable[Y]=nil end end P=nil end local r=Random.new()function RandomVectorOffset(P,Y)return((CFrame.lookAt(Vector3.new(),P)*CFrame.Angles(0,0,r:NextNumber(0,2*math.pi)))*CFrame.Angles(math.acos(r:NextNumber(math.cos(Y),1)),0,0)).LookVector end local n=require(script.Parent);(game:GetService("\082\117\110\083\101\114\118\105\099\101")).Heartbeat:Connect(function()local P,S,D=pairs(Y)while true do local Y,Q=P(S,D)if not Y then break end if Q.Enabled==true and Q.SparksN<Q.MaxSparkCount then local P=Q.LightningBolt if P.Parts[1].Parent==nil then Q:Destroy()return end local Y=P.Parts local S=#Y local D={}for P=1,#Y,1 do if Y[P].Transparency<.3 then D[#D+1]=(P-.5)/S end end local W=nil local Z=nil if#D~=0 then W=math.ceil(D[1]*Q.MaxSparkCount)Z=math.ceil(D[#D]*Q.MaxSparkCount)end for P=1,r:NextInteger(1,Q.MaxSparkCount-Q.SparksN),1 do if#D==0 then break end local b={}for P=W,Z,1 do if Q.SlotTable[P]==nil then b[#b+1]=P end end if#b~=0 then local P=b[r:NextInteger(1,#b)]local W=r:NextNumber(-0.5,.5)local Z=((P-.5)+W)/Q.MaxSparkCount local E=10 local J=1 for P=1,#D,1 do local Y=math.abs(D[P]-Z)if Y<E then E=Y J=math.floor((D[P]*S+.5)+.5)end end local C=Y[J]local k={}local v={}k.WorldPosition=C.Position+(W*C.CFrame.RightVector)*C.Size.X v.WorldPosition=k.WorldPosition+RandomVectorOffset(C.CFrame.RightVector,math.pi/4)*r:NextNumber(Q.MinDistance,Q.MaxDistance)k.WorldAxis=(v.WorldPosition-k.WorldPosition).Unit v.WorldAxis=k.WorldAxis local a=n.new(k,v,r:NextInteger(Q.MinPartsPerSpark,Q.MaxPartsPerSpark))a.MinRadius=0 a.MaxRadius=.8 a.AnimationSpeed=0 a.Thickness=C.Size.Y/2 a.MinThicknessMultiplier=1 a.MaxThicknessMultiplier=1 a.PulseLength=.5 a.PulseSpeed=r:NextNumber(Q.MinSpeed,Q.MaxSpeed)a.FadeLength=.25 local R,m,K=Color3.toHSV(C.Color)a.Color=Color3.fromHSV(R,.5,K)Q.SlotTable[P]=a end end end local W=0 for P,Y in pairs(Q.SlotTable)do if Y.Parts[1].Parent~=nil then W=W+1 else Q.SlotTable[P]=nil end end Q.SparksN=W end end)return P


local v1 = {};
v1.__index = v1;
local u1 = {};
function v1.new(p1, p2)
	local v2 = setmetatable({}, v1);
	v2.Enabled = true;
	v2.LightningBolt = p1;
	v2.MaxSparkCount = p2 or 10;
	v2.MinSpeed = 4;
	v2.MaxSpeed = 6;
	v2.MinDistance = 3;
	v2.MaxDistance = 6;
	v2.MinPartsPerSpark = 8;
	v2.MaxPartsPerSpark = 10;
	v2.SparksN = 0;
	v2.SlotTable = {};
	v2.RefIndex = #u1 + 1;
	u1[v2.RefIndex] = v2;
	return v2;
end;
function v1.Destroy(p3)
	u1[p3.RefIndex] = nil;
	for v3, v4 in pairs(p3.SlotTable) do
		if v4.Parts[1].Parent == nil then
			p3.SlotTable[v3] = nil;
		end;
	end;
	p3 = nil;
end;
local u2 = Random.new();
function RandomVectorOffset(p4, p5)
	return (CFrame.lookAt(Vector3.new(), p4) * CFrame.Angles(0, 0, u2:NextNumber(0, 2 * math.pi)) * CFrame.Angles(math.acos(u2:NextNumber(math.cos(p5), 1)), 0, 0)).LookVector;
end;
local u3 = require(script.Parent);
game:GetService("RunService").Heartbeat:Connect(function()
	local v5, v6, v7 = pairs(u1);
	while true do
		local v8, v9 = v5(v6, v7);
		if not v8 then
			break;
		end;
		if v9.Enabled == true and v9.SparksN < v9.MaxSparkCount then
			local l__LightningBolt__10 = v9.LightningBolt;
			if l__LightningBolt__10.Parts[1].Parent == nil then
				v9:Destroy();
				return;
			end;
			local l__Parts__11 = l__LightningBolt__10.Parts;
			local v12 = #l__Parts__11;
			local v13 = {};
			for v14 = 1, #l__Parts__11 do
				if l__Parts__11[v14].Transparency < 0.3 then
					v13[#v13 + 1] = (v14 - 0.5) / v12;
				end;
			end;
			local v15 = nil;
			local v16 = nil;
			if #v13 ~= 0 then
				v15 = math.ceil(v13[1] * v9.MaxSparkCount);
				v16 = math.ceil(v13[#v13] * v9.MaxSparkCount);
			end;
			for v17 = 1, u2:NextInteger(1, v9.MaxSparkCount - v9.SparksN) do
				if #v13 == 0 then
					break;
				end;
				local v18 = {};
				for v19 = v15, v16 do
					if v9.SlotTable[v19] == nil then
						v18[#v18 + 1] = v19;
					end;
				end;
				if #v18 ~= 0 then
					local v20 = v18[u2:NextInteger(1, #v18)];
					local v21 = u2:NextNumber(-0.5, 0.5);
					local v22 = (v20 - 0.5 + v21) / v9.MaxSparkCount;
					local v23 = 10;
					local v24 = 1;
					for v25 = 1, #v13 do
						local v26 = math.abs(v13[v25] - v22);
						if v26 < v23 then
							v23 = v26;
							v24 = math.floor(v13[v25] * v12 + 0.5 + 0.5);
						end;
					end;
					local v27 = l__Parts__11[v24];
					local v28 = {};
					local v29 = {};
					v28.WorldPosition = v27.Position + v21 * v27.CFrame.RightVector * v27.Size.X;
					v29.WorldPosition = v28.WorldPosition + RandomVectorOffset(v27.CFrame.RightVector, math.pi / 4) * u2:NextNumber(v9.MinDistance, v9.MaxDistance);
					v28.WorldAxis = (v29.WorldPosition - v28.WorldPosition).Unit;
					v29.WorldAxis = v28.WorldAxis;
					local v30 = u3.new(v28, v29, u2:NextInteger(v9.MinPartsPerSpark, v9.MaxPartsPerSpark));
					v30.MinRadius = 0;
					v30.MaxRadius = 0.8;
					v30.AnimationSpeed = 0;
					v30.Thickness = v27.Size.Y / 2;
					v30.MinThicknessMultiplier = 1;
					v30.MaxThicknessMultiplier = 1;
					v30.PulseLength = 0.5;
					v30.PulseSpeed = u2:NextNumber(v9.MinSpeed, v9.MaxSpeed);
					v30.FadeLength = 0.25;
					local v31, v32, v33 = Color3.toHSV(v27.Color);
					v30.Color = Color3.fromHSV(v31, 0.5, v33);
					v9.SlotTable[v20] = v30;
				end;
			end;
		end;
		local v34 = 0;
		for v35, v36 in pairs(v9.SlotTable) do
			if v36.Parts[1].Parent ~= nil then
				v34 = v34 + 1;
			else
				v9.SlotTable[v35] = nil;
			end;
		end;
		v9.SparksN = v34;	
	end;
end);
return v1;
