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.
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