EvLightning is a Roblox Lua library. Its purpose is to generate realistic-looking lightning bolts. This could be used to easily add lightning strike effects to any game
Please do not use game.Workspace, as Workspace can be renamed. Instead use game:GetService("Workspace") or workspace
Instead of instantiating a part with inline default values, please create a global partTemplate and Clone() it and change its properties as appropriate. Also, please do not mix string enums with enums (style issue). Also, please set the parent last, as it is much faster to do so. This should also be encouraged by the use of Clone():
localpartTemplate=Instance.new("Part")
partTemplate.Anchored=truepartTemplate.CanCollide=falsepartTemplate.BrickColor=BrickColor.new("White")
partTemplate.Material=Enum.Material.NeonpartTemplate.TopSurface=Enum.SurfaceType.SmoothpartTemplate.FormFactor=Enum.FormFactor.CustompartTemplate.BottomSurface=Enum.SurfaceType.Smooth-- within function LightningBolt:Draw(parent)localpart=partTemplate:Clone()
ifself.options.colorthenpart.BrickColor=self.options.colorendifself.options.materialthenpart.Material=self.options.materialendpart.Size=Vector3.new(1-line.depth*2*0.1, 1-line.depth*2*0.1, (line.origin-line.goal).magnitude+0.5)
part.CFrame=CFrame.new((line.goal+line.origin)/2, line.goal)
part.Transparency=line.transparencypart.Parent=model
Please do not iterate through arrays using pairs. This will make the ghost of simple for loops come for you.
fori=1, #tdoprint(t[i])
end
When constructing a new array, especially when it's a copy, repeatedly doing #t for every write operation is going to make my head spin. For a non-copy, a count variable is preferable. A copy can easily be written as so:
localrunLines= {}
fori=1, #self.linesdorunLines[i] =self.lines[i]
end
If you want a method function to be strictly internal, you might consider to do the following:
functionLightningBolt:generateBolt() -- What you havelocalfunctiongenerateBolt(self) -- A way to truly hide API you don't want exposed
Please be consistent on your spacing around binary operators. "3 + 5" or "3+5", but pick one and stick with it.
This information is already contained within the comments of the module. Why would it ever be necessary to have this?
LightningBolt._version=1
It is STRONGLY preferable to not recursively generate objects within objects (#L134). If possible, please avoid unnecessary abstraction for internal syntactic sugar. Only do it if you absolutely have to.
Color is preferable to BrickColor (API change request)