Laser beam with multiple parts

I have been looking on the dev forum and I found this post about what I have in mind it was vague of how they found the solution since they just posted the script. I was trying to understand it since it wouldn’t work since it had variables not included. Is there any one that could help me solve this with an explanation.

What I have in mind random amount of parts and random on the x,y,z axis.

1 Like

The link if anyone would have an explanation on how this would work since I do not know and because of the unknown variables.

Could anyone help since I am trying to make lightning from the sky.

1 Like

I have a script where I tried to make it but it won’t split between the two parts (red and green).
The test place if anyone wants to test and help : LightningTest.rbxl (22.9 KB)

local partA = game.Workspace:WaitForChild("PointA")
local partB = script.Parent
local Folder = game.Workspace:WaitForChild("Lightning Prototype")
local Ray_Folder = game.Workspace:WaitForChild("Visualize the Ray")

local new_Params = RaycastParams.new()
new_Params.FilterDescendantsInstances = {partA, Folder, Ray_Folder}
new_Params.FilterType = Enum.RaycastFilterType.Blacklist
local origin = partA.CFrame.p
local direction = (partB.CFrame.p - origin)
local Make_Ray = workspace:Raycast(origin, direction, new_Params)

if Make_Ray then
	print(Make_Ray)
	print(Make_Ray.Instance)
	print(Make_Ray.Position)
	print(Make_Ray.Material)
	--print("true")
else
	Make_Ray = {}
	Make_Ray.Position = origin + direction
end

local LRandom = math.random(1,5)
local Divise_Distance = Make_Ray.Position/LRandom

for make_parts = 1, LRandom do
	print("parts")
	local Distance = (origin - Divise_Distance).Magnitude
local Visualize = Instance.new("Part", game.Workspace)
Visualize.Name = ("Visualize Ray")
Visualize.Anchored = true
Visualize.CanCollide = false
Visualize.Size = Vector3.new(0.2,0.2,Distance)
Visualize.CFrame = CFrame.lookAt(origin, partB.CFrame.p) * CFrame.new(0,0,-Distance/2)
Visualize.Color = Color3.fromRGB(39, 147, 255)
	Visualize.Material = Enum.Material.Neon
end

Could anyone help with this it is in the old script but how would I make the blue parts not go past the the red and green part?

LRandom = math.random(1,10)
local Twodivise_Distance = (Make_Ray.Position + origin)/2--(Make_Ray.Position - origin).unit/LRandom

for make_parts = 1, LRandom do
	print("parts".. make_parts)
local Divise_Random = math.random(1, 10)
print(Divise_Random)
local Divise_Distance = Twodivise_Distance+(Make_Ray.Position - origin)/Divise_Random--[[(Twodivise_Distance-(Make_Ray.Position + origin))/Divise_Random]]
local Distance = (origin - Divise_Distance).Magnitude
local Visualize = Instance.new("Part", Ray_Folder)
Visualize.Name = ("Visualize Ray".. make_parts)
Visualize.Size = Vector3.new(0.75,0.75,0.75
Visualize.CFrame = CFrame.new(Divise_Distance)