Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

How to "link" parts using "lightning code" continuously?

Asked by 6 years ago

Lightning uses what I would call "Linear Linking" where there is a starting point and a desired target point such as:

function Lightning(pos,pos2,radius,numParts,model)
    radius = radius or 0.2
    numParts = numParts or 10
    model = model or workspace
    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

However, I am trying to loop this to create a chain of some sort- my goal is to make this bolt "orbit" or "emit" around/from a player- however, defining the positions beforehand only makes it shoot in one general direction. Please help!

Answer this question