Hi Everyone!, this is tutorial for my previous system of generating lightning bolts or arc beams.
- Make two parts, finish and start. It have to be anchored !
- Insert script inside a game where you script your parts, you can do this for guns and tools where the finish is mouse hit position and start is tool handle
SCRIPTING:
- we need to create a variables
local model = workspace.Model ---- insert your model here
local number = 5 ----- number of points are you creating
local index = 0 ---- an index that are gaps beetween each point
local start = workspace.Part1 --- replace it with your start part
local finish = workspace.Part2 --- replace with finish part
Okay! we created all we need to create a loops
for i = 1, number do
local part = Instance.new("Part",script.Folder) --- you can change parent
part.Anchored = true
part.CanCollide = false
part.Size = Vector3.new(1,1,1)
part.Transparency = 0 --------- you can change it
part.BrickColor = BrickColor.new("New Yeller") --- customizable
part.Material = "Neon" --- also you can change it
end
When we maked a part, next step is add a position to this part
3.
start.CFrame = CFrame.lookAt(start.Position,Finish.Position)
part.CFrame = start.CFrame
part.Position = part.Position + start.CFrame.LookVector * index
part.CFrame = part.CFrame * CFrame.new(math.random(-1,1),math.random(-1,1),0) --- don't change it, the look vector is Z axis and it can break the script
index = index + (start.Position - finish.Position).Magnitude/number
if (part.Position - start.Position).Magnitude < ((start.Position - finish.Position).Magnitude/number) then
part:Destroy()
end
wait(0.1)
now we have point generation
4.
wait(0.1)
for _, v in pairs(script.Folder:GetChildren()) do
if v and v:IsA("BasePart") and (script.Folder:GetChildren()[_-1]) ~= nil then
v.CFrame = CFrame.lookAt(v.Position,script.Folder:GetChildren()[_-1].Position)
local midpoint = (script.Folder:GetChildren()[_-1].Position + v.Position)/2
local bolt = Instance.new("Part",script.Folder)
bolt.Anchored = true
bolt.CanCollide = false
bolt.Size = Vector3.new(0,0,(script.Folder:GetChildren()[_-1].Position - v.Position).Magnitude) --- experiment with magnitude, try paste it to axis
bolt.Position = midpoint
bolt.CFrame = CFrame.lookAt(v.Position)
--------------- paste here another variables like material or color
elseif (script.Folder:GetChildren()[_-1]) == nil then
v.CFrame = CFrame.lookAt(v.Position,start.Position)
wait(0.1) -- you can delete it, but is not recommended
end
end
There we go, if you wan’t. you can add more things like, corountines or make more effects, but is basics of this sytem. sorry for my english and i’m think i help you. Bye