function fire(a,b) local last=a; local size=((a-b).magnitude)/50; while((b-last).magnitude>size)do local p=script.p:Clone(); p.Parent = game.Workspace.lightning; p.formFactor=3; p.Size=Vector3.new(.25,.25,size); p.Anchored=true; p.CanCollide=false; p.Transparency=0; p.Name='wt'; local x=math.rad(math.random(-15,15))*-5; local y=math.rad(math.random(-7.5,7.5))*-2.5; local z=math.rad(math.random(-10,10))*-1.5; p.CFrame=CFrame.new(last,b)*CFrame.Angles(x*0.5 + y,y*1.25,z)*CFrame.new(0,0,-(size/2.5)); p.BrickColor=BrickColor.new(1); local pp=script.PointLight:Clone(); pp.Parent = p last=(p.CFrame*CFrame.new(0,0,-(size/2))).p; end; end; while script.Parent ~= nil do fire(game.Workspace.F1.Rod.Wire.Position,game.Workspace.F2.Rod.Wire.Position) wait() for i,v in ipairs (game.Workspace.lightning:GetChildren()) do if v:IsA("BasePart") then v:Destroy() end end end
I'd want to turn this into a module script so I could just use the "fire(a,b)" function without having to repaste the code every time.
In a module script just return what you want to use in other scripts.
So inside of a module script:
function fire(a,b) local last=a; local size=((a-b).magnitude)/50; while((b-last).magnitude>size)do local p=script.p:Clone(); p.Parent = game.Workspace.lightning; p.formFactor=3; p.Size=Vector3.new(.25,.25,size); p.Anchored=true; p.CanCollide=false; p.Transparency=0; p.Name='wt'; local x=math.rad(math.random(-15,15))*-5; local y=math.rad(math.random(-7.5,7.5))*-2.5; local z=math.rad(math.random(-10,10))*-1.5; p.CFrame=CFrame.new(last,b)*CFrame.Angles(x*0.5 + y,y*1.25,z)*CFrame.new(0,0,-(size/2.5)); p.BrickColor=BrickColor.new(1); local pp=script.PointLight:Clone(); pp.Parent = p last=(p.CFrame*CFrame.new(0,0,-(size/2))).p; end; end; while script.Parent ~= nil do fire(game.Workspace.F1.Rod.Wire.Position,game.Workspace.F2.Rod.Wire.Position) wait() for i,v in ipairs (game.Workspace.lightning:GetChildren()) do if v:IsA("BasePart") then v:Destroy() end end end return fire
Then inside the other script
local fire = require(game.ServerScriptStorage.WhateverYouNamedIt) fire(x,y)
copy and paste it into a module script?