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)