How can i place parts in a straight line from one point to another?

I am trying to place parts from point 1 to point 2 via scripting with each part being getting closer to point 2 like in the images below



i have no idea how to do it so if you could help me i would really appreciate it C:

I have got the solution, but ill hide it so you can figure it out yourself, heres some tips:

Try using a variable to decide how much parts are present, and their distances.

get the distance and direction vectors and multiply them by the iteration, the direction, and the distance between parts.

If your really stuck, heres the solution:

Solution
local startpart = workspace.start
local endpart = workspace.endp

local partsfolder = workspace.parts

local distance, direction = (endpart.Position - startpart.Position).Magnitude, (endpart.Position - startpart.Position).Unit

local studsbetweenpart = 5
local amountofparts = math.floor(distance / studsbetweenpart)

for i = 1, amountofparts do
	local part = Instance.new("Part", partsfolder)
	part.Anchored = true
	part.Size = Vector3.new(1,1,1)
	part.Position = startpart.Position + direction * i * studsbetweenpart 
end

Also should be in Scripting Support

yayyyy c:


i only figure things out when i have previously done something similar lol- i had no idea how to get the direction or what to do with it since i’ve never worked with these, regarldess tysm i learnt so much building the script myself, ill mark you as the solution ^ ^

1 Like

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.