Divide the rays mag by the number points you want along your ray then multiply it by your iteration in the for loop

for i=1, totalNumberOfPoints do
local scalar = ( ray.magnitude / totalNumberOfPoints ) * i
--# Next apply your offset to that position
--# after you apply offset, create a part halfway between that position and the last iterations position.
--# and make the size of that part be the rays magnitude divided by total number of points
--# The direction of the part should be the the distance from the last iteration and the current iteration declared as a unit vector
end

You can get the length of the ray and then divide it by the spacing you want between each zig zag to get the number of points. Then at you can use CFframe.lookvector to line it up and add a slightly randomised CFrame (Only 2 axis) to off set it to the side and up.

from there you could create rods between each of the parts you create.

How do I get the positions if position is a magnitude?

local ignore = {game.Workspace.SpellEffects,plr.Character}
local ray = Ray.new(start,(ending-start)*range)
local hit,hitpos,normal = game.Workspace:FindPartOnRayWithIgnoreList(ray,ignore)
local distance = (hitpos-start).magnitude
for i=1, 10 do
local position = ( distance / 10 ) * i
local Offset = math.random()
position = position + Vector3.new(Offset,Offset,Offset)
local Part = Instance.new("Part",workspace)
Part.Anchored = true
Part.BrickColor = BrickColor.new("Really red")
Part.Anchored = true
Part.Position = position
Part.Size = Vector3.new(1,1,1)
--# after you apply offset, create a part halfway between that position and the last iterations position.
--# and make the size of that part be the rays magnitude divided by total number of points
--# The direction of the part should be the the distance from the last iteration and the current iteration declared as a unit vector
end

So it goes in the opposite direction, I’m not very good with magnitudes and CFrames, it also ignores my start point and just goes from the middle of the baseplate. I really appreciate your help.

local ignore = {game.Workspace.SpellEffects,plr.Character}
local ray = Ray.new(start,(ending-start)*range)
local hit,hitpos,normal = game.Workspace:FindPartOnRayWithIgnoreList(ray,ignore)
local distance = (start-hitpos).magnitude
local direction = (start-hitpos).Unit
for i=1, 10 do
local position = ( distance / 10 ) * i
local Offset = math.random(1,2)
position = direction*position + Vector3.new(Offset,Offset,Offset)
local Part = Instance.new("Part",workspace)
Part.Anchored = true
Part.BrickColor = BrickColor.new("Really red")
Part.Position = position
Part.Size = Vector3.new(1,1,1)

also. You wanna add these positions from the position you shot the ray at. I know its a lot. Or you can just use ToObjectSpace. whatever floats your boat /shrug

This is where it gets a little bit tricky, but it shouldnt be to difficult so bare with me.

--# We can conclude in order to get the last position in the iteration we can do...
local lastScalar = (distance / 10) * (i - 1)
local lastPosition = CFrame.new(direction*lastScalar+offset):toOjectSpace(CFrame.new(start))
--# We then need to find the position which is in the middle of the last position and the current position
--# Ill leave this as an exercise to you. After you do this, we can then worry about direction, gl. ;).

I kinda changed it so it has always got even spacing. If it’s the first position then theirs no last part so what happens then. If I saved the positions in a table then I could get the last pos by doing table[number-1] ??

local ignore = {game.Workspace.SpellEffects,plr.Character}
local ray = Ray.new(start,(ending-start)*range)
local hit,hitpos,normal = game.Workspace:FindPartOnRayWithIgnoreList(ray,ignore)
local distance = (start-hitpos).magnitude
local direction = (start-hitpos).Unit
local number = 0
while true do
wait(.1)
number = number + 1
local position = ( 10 ) * number
local offset = math.random(1,2)
local pos = position*direction+Vector3.new(offset,offset,offset)
print(pos)
local Part = Instance.new("Part",workspace)
Part.Anchored = true
Part.BrickColor = BrickColor.new("Really red")
Part.CFrame = CFrame.new(pos):ToObjectSpace(CFrame.new(start))
Part.Size = Vector3.new(1,1,1)
end

A for loop is much better in this regard. also if your worried about thier not being a first point, dont be. This will be fixed when we actually connect the points

I’m mixed up, I think I got it but somethings are vector 3’s and others are cframe’s. read the comments

local number = 0
local positions = {}
table.insert(positions,0,startcframe)
while true do
wait(.1)
number = number + 1
local position = ( 10 ) * number
local offset = math.random(1,2)
local pos = position*direction+Vector3.new(offset,offset,offset)
print(pos)
local Cframe1 = CFrame.new(pos):ToObjectSpace(CFrame.new(start))
table.insert(positions,number,Cframe1)
print(positions[number])
local lastposition = positions[number-1]
local length = (positions[number-1]-positions[number]).magnitude --it says argument 2 vector 3 expected?
local Part = Instance.new("Part", game.Workspace.SpellEffects)
Part.Anchored = true
Part.Size = Vector3.new(0.1,0.1,length)
Part.CFrame = lastposition
end

local ignore = {game.Workspace.SpellEffects,plr.Character}
local ray = Ray.new(start,(ending-start)*range)
local hit,hitpos,normal = game.Workspace:FindPartOnRayWithIgnoreList(ray,ignore)
local distance = (start-hitpos).magnitude
local direction = (start-hitpos).Unit
local number = 0
local positions = {}
table.insert(positions,0,startcframe)
while true do
wait(.1)
number = number + 1
local position = ( 10 ) * number
local offset = math.random(1,2)
local pos = position*direction+Vector3.new(offset,offset,offset)
print(pos)
local Cframe1 = CFrame.new(pos):ToObjectSpace(CFrame.new(start))
table.insert(positions,number,Cframe1)
print(positions[number])
local lastposition = positions[number-1]
local length = (positions[number-1].p-positions[number].p).magnitude
local Part = Instance.new("Part", game.Workspace.SpellEffects)
Part.Anchored = true
Part.Size = Vector3.new(0.1,0.1,length)
Part.CFrame = lastposition
end

I’ll let you figure out how to orientate it using what you’ve learned.

Remember that you can get direction by doing (start-end).unit
Effectively you want to get the direction between the current position and last position.

After this you can create your CFrame for your part.
Remember, that direction is a unit vector and you will need to multiply it by a scalar in order to get a non unit vector with size.
Be sure to show me the finished project