I have a script that can launch a Lightning by hand to the desired place, but there is a problem in the vector that will position it in a certain position of the map.
how can I fix?
The script:
math.randomseed(tick())
function lightning(startPos,endPos,details)
local mag = (startPos-endPos).magnitude
local step = details.Step
local waitTime = details.WaitTime
local lightningModel = Instance.new("Model" , workspace)
lightningModel.Name = "Lightning"
local lastStart = startPos
local debugMode = details.DebugMode
local lightningEnd = endPos
for i = 1,mag,mag/step do
print(i)
if waitTime > 0 then
wait(waitTime)
end
local newEnd = endPos*Vector3.new(math.random(-2*mag/5,2*mag/5),math.random(-2*mag/5,2*mag/5),0)
if i+(mag/step) == mag then
print("LAST ONE")
newEnd = endPos
end
local ray = Ray.new(lastStart,(newEnd-lastStart).unit*(mag/step))
local hit,rayEnd = workspace:FindPartOnRay(ray,(lightningModel))
local currentMag = (lastStart-rayEnd).magnitude
local part = Instance.new("Part")
part.Anchored = true
part.CanCollide = false
part.TopSurface = "Smooth"
part.BottomSurface = "Smooth"
part.FormFactor = "Custom"
part.BrickColor = BrickColor.new(details.Color)
part.Material = details.Material
part.Transparency = details.Transparency
part.Size = Vector3.new(.2,.2,currentMag)
part.CFrame = CFrame.new(lastStart , rayEnd)*CFrame.new(0,0,-currentMag/2)
part.Parent = lightningModel
lastStart = rayEnd
if debugMode then
local p = Instance.new("Part")
p.FormFactor = "Custom"
p.Size = Vector3.new(.2,.2,.2)
p.Anchored = true
p.Material = "Neon"
p.Position = rayEnd
end
lightningEnd = rayEnd
end
return lightningModel,lightningEnd
end
return lightning
Full module >.>

7 comments
You need to include way more of your code and actually explain what's going on
ok
:P try to understand now
You need to include ALL code necessary for us to answer this. I see there's a function lightning(), however I see no define function.
Need more code post all of your code so we can actually understand what is going on and the error from output
well if it is to fix
You need Local script too?