You can write your topic however you want, but you need to answer these questions:
What do you want to achieve? I want to be able to calculate the distance between 2 GUI frames
What is the issue? It keeps returning 0
What solutions have you tried so far? I’ve searched around a bit. My first idea came from a scripting helpers forum post. And that hasn’t worked I’m just sorta stuck now.
function RenderLine()
for i,lin in pairs(lines) do
local line = drawLine:Clone()
local firstVec = lin.FP.AbsolutePosition
local secVec = lin.SP.AbsolutePosition
local distance = (firstVec - secVec).magnitude
print(distance)
end
end
function spawnLine()
if lastPoint ~= nil and currentPoint ~= nil then
table.insert(lines,{FP = lastPoint,SP = currentPoint})
end
end
local Frame1 = script.Parent.Frame1
local Frame2 = script.Parent.Frame2
function CalculateDistance()
local distance = Frame1.AbsolutePosition - Frame2.AbsolutePosition
return distance
end
print(CalculateDistance())
I know what the issue is but i dont know how to fix it. Im setting 2 values, CurrentPoint and LastPoint
But by the time i call the RenderLine() function for some reason its set them to the same frame.
Heres my renderPoints() function
function RenderPoints()
area:ClearAllChildren()
for i,pt in pairs(points) do
local p = point:Clone()
currentPoint = p
p.Parent = area
p.Position = UDim2.new(0,p.AbsoluteSize.X * i + padding * (i - 1),0,area.AbsoluteSize.Y - pt.CAm - p.AbsoluteSize.Y / 2)
p.ValueText.Text = pt.CAm
lastPoint = p
end
end
local Frame1 = script.Parent.Frame1
local Frame2 = script.Parent.Frame2
function CalculateDistance(Point1, Point2)
local distance = UDim2.new(0, Frame1.AbsolutePosition.X - Frame2.AbsolutePosition.X, 0, Frame1.AbsolutePosition.Y - Frame2.AbsolutePosition.Y)
return distance
end
function SetLineGraph()
local pos = CalculateDistance(Frame1, Frame2)
local GraphLine = Instance.new("Frame", script.Parent)
GraphLine.AnchorPoint = Vector2.new(0.5, 0.5)
GraphLine.Position = UDim2.new(0,(Frame1.AbsolutePosition.X + Frame1.AbsoluteSize.X/2) - pos.X.Offset/2
,0,(Frame1.AbsolutePosition.Y + Frame1.AbsoluteSize.Y/2) - pos.Y.Offset/2)
if pos.X.Offset <= pos.Y.Offset then
GraphLine.Size = UDim2.new(0,pos.Y.Offset,0,5)
else if pos.X.Offset > pos.Y.Offset then
GraphLine.Size = UDim2.new(0,pos.X.Offset,0,5)
end
end
end
SetLineGraph()
It simply takes the position of two frames calculates the middle position of it and sets a frame at this position. The rotation isn’t adjusted so you have to do that.
Edit: I overworked that and removed some lines but should work like before.
Ended up being an issue with how the previous and current positions were being stored.
i changed it up a bit to keep track of the positions of the most recent two dots created and put their positions in variables called: previousPosition and currentPosition