I wrote a function that generates lightning using lookVector, etc, and when I call the function I get the following error
Workspace.Player.Right Leg.Wall2:9: bad argument #1 to 'new' (Vector3 expected, got nil)
(Line 9 in the error is line 5 in the below code) I have no idea how to rectify this. 'Wall' Is the LocalScript in which this function is contained. Here is the function just in case it is needed:
function Lightning(pos,pos2,radius,numParts,model)
radius = 0.2
numParts = 5
model = game.Players.LocalPlayer.Character
local lv = CFrame.new(pos,pos2).lookVector
local dist = (pos-pos2).magnitude
local dbp = dist/numParts
local last = pos
for i = 1,numParts do
local p = Instance.new("Part",model)
p.FormFactor = "Symmetric"
p.Size = Vector3.new(1,1,1)
p.CanCollide = false
p.Anchored = true
p.BrickColor = BrickColor.new("Bright red")
local x = math.random(-100,100)/100*dbp/2
local y = math.random(-100,100)/100*dbp/2
local p2 = CFrame.new(pos+lv*(i*dbp),pos2+lv)*CFrame.new(x,y,0)
local dist2 = (p2.p-last).magnitude
local mid = (p2.p+last)/2
local m = Instance.new("BlockMesh",p)
m.Scale = Vector3.new(radius,radius,dist2)
p.CFrame = CFrame.new(mid,p2.p)
last = p2.p
game:GetService("Debris"):AddItem(p,math.random(40,100)/1000)
end
end
Help would be appreciated. Thanks.

6 comments
The error isn't in the lightning function.
That is where you are wrong, the error specifically tells me Line 9 (line 5 here)
What arguments are you giving for pos1 and pos2?
There are more efficient ways of constructing a unit vector between two points...
Well I'm not very good at scripting and I only made this with help.
How are you calling the Lightning function?