Creating a part going from Part A to Part B

So, basically I’m trying to make a part size to make a beam/line going from PartA to PartB.

Something like this:

But, instead of using a beam, I want a script to create a part and make it a line from Part A, to Part B.

I’ve tried looking at google, and the devforum.

You don’t have to write an entire script, just more telling me what I should subtract, multiply, etc.

This is a function I use when I need to visualize things like a ray:

local function VisualizeLine(pos1,pos2, part:BasePart?)
	local p = part or Instance.new("Part")
	p.Name = "visual"
	p.Anchored = true


	local distance = (pos1 - pos2).Magnitude 



	p.Size = Vector3.new(size, size, distance)
	p.CFrame = CFrame.new(pos1, pos2) * CFrame.new(0, 0, -distance / 2) 
	p.Parent = workspace.Visual

	return p
end

Thank’s! I’ll try it out. Hopefully it work’s.

make sure to replace the size variable to how “thick” you want the part to be (small number is advised to replicate a “line”). Personally I use 0.01

I tried it and it didn’t work, it was probably just my coding but, here’s the script I have;

local function VisualizeLine()
	local visulaizer = game.Workspace.Visual
	local p1 = game.Workspace.Part
	local p2 = game.Workspace.Part2
	local pos1 = p1.Position
	local pos2 = p2.Position


	local distance = (pos1 - pos2).Magnitude 



	visulaizer.Size = Vector3.new(p1.Size, p2.Size, distance)
	visulaizer.CFrame = CFrame.new(pos1, pos2) * CFrame.new(0, 0, -distance / 2)
end

game:GetService("RunService").Heartbeat:Connect(VisualizeLine)

This line here is the problem:

visulaizer.Size = Vector3.new(p1.Size, p2.Size, distance)

it needs a number not a vector3

Here is my result after changing your code a bit:

local function VisualizeLine()
	local visulaizer = game.Workspace.Visual
	local p1 = game.Workspace.Part
	local p2 = game.Workspace.Part2
	local pos1 = p1.Position
	local pos2 = p2.Position


	local distance = (pos1 - pos2).Magnitude 



	visulaizer.Size = Vector3.new(0.1, 0.1, distance)
	visulaizer.CFrame = CFrame.new(pos1, pos2) * CFrame.new(0, 0, -distance / 2)
end

game:GetService("RunService").Heartbeat:Connect(VisualizeLine)

Result:

1 Like

I’m back, And it WORKED!!! Thank you so much!