Creating a ruler tool

so far im currently trying to have one part of the part anchored while it resizes to the new target, here’s what i’ve thrown at the wall so far

local tool = script.Parent
local ReplicatedStorage = game:GetService("ReplicatedStorage")
local RulerStorage = ReplicatedStorage:WaitForChild("Rulers")
local RealRulerStorage = workspace:WaitForChild("Rulers")
local Area = RulerStorage:WaitForChild("Area")
local RunService = game:GetService("RunService")
local player = game:GetService("Players").LocalPlayer
local baseruler = RulerStorage:WaitForChild("Ruler")

local xRuler:Part?
local xRulersFarLeftSide:Attachment?
local xRulersFarRightSide:Attachment?
local xRulersLength:TextLabel?
-- stupidly long names my beloved
local xRulersLengthsConstantUpdates:RBXScriptConnection?
local zRuler:Part?
local zRulersFarLeftSide:Attachment?
local zRulersFarRightSide:Attachment?
local zRulersLength:TextLabel?
local zRulersLengthsConstantUpdates:RBXScriptConnection?
local areasConstantUpdate:RBXScriptConnection?
-- if any rulers are in use
local UsinXAxisRuler = false
local UsinZAxisRuler = false
-- display the area
local AreaTime = false

tool.Activated:Connect(function()
	local mouse = player:GetMouse()
	if workspace:FindFirstChild("NoClipPart") then
		mouse.TargetFilter = workspace:FindFirstChild("NoClipPart")
	end
	local target = mouse.Target
	-- create the new ruler...
	if not UsinXAxisRuler and not UsinZAxisRuler and target then
		UsinXAxisRuler = true
		xRuler = baseruler:Clone()
		xRulersLength = xRuler.Length.BillboardGui.TextLabel
		xRulersLengthsConstantUpdates = RunService.PreRender:Connect(function()
			xRulersLength.Text = math.round(xRuler.Size.X).." studs long"
		end)
		xRulersFarLeftSide = xRuler.FarLeft
		xRulersFarRightSide = xRuler.FarRight
		-- do some math
		local targetCFrame = target.CFrame
		-- the farright side is now at the center of the target's CFrame, and the rest moved along with it
		xRuler.CFrame = targetCFrame * xRulersFarRightSide.CFrame:Inverse()
		-- get it out of the center!
		xRuler.CFrame += Vector3.new(0, 0.55, 0)
		xRuler.Parent = RealRulerStorage
		mouse.TargetFilter = xRuler
		local breakloop = true
		mouse.Button1Down:Once(function()
			breakloop = false
		end)
		-- max and min size
		local min = 0.05
		local max = 2047
		while breakloop do
			local target:Part = mouse.Target
			if not target then
				task.wait()
				continue
			end
			-- world positions
			local startPos = xRulersFarLeftSide.WorldPosition
			local endPos = target.Position

			local length = math.clamp((endPos - startPos).Magnitude, min, max)
			xRuler.Size = Vector3.new(length, xRuler.Size.Y, xRuler.Size.Z)
			local midPos = (startPos + endPos) / 2
			local direction = (endPos - startPos).Unit
			xRuler.CFrame = CFrame.fromMatrix(midPos, direction, Vector3.new(0,1,0):Cross(direction), Vector3.new(0,1,0))
			task.wait()
		end
	end
end)

Try this:

local selector1 = workspace:WaitForChild("sel1")

local selector2 = workspace:WaitForChild("sel2")

local ruler = workspace:WaitForChild("ruler")

game:GetService("RunService").Heartbeat:Connect(function()
	local pos1 = selector1.Position
	
	local pos2 = selector2.Position
	
	local midpoint = (pos1+pos2) / 2
	
	local length = (pos2-pos1).Magnitude
	
	ruler.CFrame = CFrame.lookAt(midpoint,pos2)
	
	ruler.Size = Vector3.new(1,1,length)
end)

Just modify the variable names to whatever you need. Selector1 and 2 are simply parts I used to be able to modify the endpoints.

I’m just going to try to use beams instead of a part now :worm::worm::worm:

Yes, but if you want to still use a part, this will work.