Making a part fit between 2 points

Eyo!

So basically I want to make a part join between 2 positions (in this case it is 2 parts). So far I’ve figured out how to get the length of the part and make it so it corresponds to the distance between both parts. HOWEVER, I now need to find a way to make it so it orientates to fit between them.

local One = script.Parent.Part
local Two = script.Parent.Part2

local Part = Instance.new("Part", script.Parent)
Part.Anchored = true
Part.Size = Vector3.new((One.Position - Two.Position).Magnitude, 0.5, 0.05)

There is my code so far

image
Here is the model it’s inside :happy1:

3 Likes

I believe you could use some simple CFrame logic to achieve this:

Part.CFrame = CFrame.new(One.Position, Two.Position)

basically it creates a cframe at position one, looking towards position two.

With a bit of CFrame manipulation, you can achieve your desired result:

local dist = (One.Position - Two.Position).Magnitude
Part.Size = Vector3.new(0.05, 0.5, dist)
Part.CFrame = CFrame.new(One.Position, Two.Position) * CFrame.new(0, 0, -dist/2)
9 Likes

That worked for me : )
Thanks!

is there any way i could rotate this so then i can make the bottom of a part be at one point and the top at the other point?