Create a line between two points

I’m currently creating a game and I need to create a link between a point and another point.

It also is made by the player so it starts when they press down on the object.
And when you release it it stops creating it.
Here is my current code but it just currently makes a tiny line (around 1 pixel long) and in the wrong position

local UserInputService = game:GetService("UserInputService")

local MainFrame = script.Parent
local Toucher = script.Parent

local Camera = workspace:WaitForChild("Camera")

local DragMousePosition
local FramePosition
local Snapping=false
local itself

local Draggable = false


function linecreate(p1, p2)
	local v = (p2 - p1)
	local f = Instance.new("Frame")
	f.Size = UDim2.new(0, v.magnitude+ 1, 0, 2)
	f.Position = UDim2.new(0,(p1.x + v.x/2) - f.Size.X.Offset * 0.5, 0, (p1.y + v.y/2) - f.Size.Y.Offset * 0.5)
	f.Rotation = math.deg(math.atan2(v.y, v.x))
	f.BorderSizePixel = 0
	f.BackgroundColor3 = Color3.new()
	local files = game.ReplicatedStorage.Templates["Wire files"]:Clone()
	files.Parent = f
	return f
end


Toucher.InputBegan:Connect(function(input)
	if input.UserInputType == Enum.UserInputType.MouseButton1 or input.UserInputType == Enum.UserInputType.Touch then
		Draggable = true
		
		
		
		DragMousePosition = Vector2.new(input.Position.X,input.Position.Y)
		FramePosition = Vector2.new(MainFrame.Position.X.Scale,MainFrame.Position.Y.Scale)
	end
end)

Toucher.InputEnded:Connect(function(input)
	if input.UserInputType == Enum.UserInputType.MouseButton1 or input.UserInputType == Enum.UserInputType.Touch then
		if Draggable == true then
			Draggable = false
		end
	end
end)


UserInputService.InputChanged:Connect(function(input)
	if Draggable == true then
		local NewPosition = FramePosition + ((Vector2.new(input.Position.X,input.Position.Y))/Camera.ViewportSize)
		print(NewPosition)
		print(FramePosition)
		local line = linecreate(FramePosition, NewPosition)
		line.Parent = script.Parent.Parent.Parent
	end 
end)

And ideas on what is going wrong and how I can make it better?

This has already been solved inside another post:

sometimes it’s better to make a quick google search before creating a topic.

3 Likes