Asking again because development has completely hauled in light of this, thus it is quite urgent.
I'm trying to make a graph that shows ping, it is working (all be it very slowly) but i'm having a problem getting rid of the segments I draw after they are off screen. Right now I have a script in each segment I draw that destroys them when they go farther then the background of the graph. When the bars get far enough that they would have been removed the game crashes.
I have a suspicion it has to do with the fact I'm using AbsolutePosition because I've never really had a good experience with it in the past. I would use something else but I don't think there is a way. The graph boundaries scale with the users window size but the lines will always remain one pixel wide (as well as using offset instead of scale to move them), so using any other positioning method wouldn't account for that.
Here is the code contained in each segment:
function Move()
if tonumber(script.Parent.AbsolutePosition.X) < tonumber(script.Parent.Parent.Parent.Back.AbsolutePosition.X) then
script.Parent:Destroy()
end
end
script.Parent.Changed:Connect(Move)
And here is the code I use to draw them, just in case you need it:
local TweenService = game:GetService("TweenService")
local NameList = {0}
while true do
script.Parent.Back.Position = UDim2.new(0, script.Parent.Back.Position.X.Offset - 1, 0, 0)
if script.Parent.Back.Position.X.Offset <= -40 then
script.Parent.Back.Position = UDim2.new(0, 0, 0, 0)
end
local Plots = script.Parent.Plots:GetChildren()
for i=1,#Plots do
Plots[i].Position = UDim2.new(1, Plots[i].Position.X.Offset - 1, Plots[i].Position.Y.Scale, 0)
end
local CurrentPosition = Vector2.new(0, 1 - (script.Parent.Ping.Value / 200))
local DataPoint = script.LineSegment:Clone()
DataPoint.Position = UDim2.new(1, 0, 1 - (script.Parent.Ping.Value / 200), 0)
DataPoint.Size = UDim2.new(0, 1, (script.Parent.Ping.Value / 200), 0)
DataPoint.Parent = script.Parent.Plots
DataPoint.BackgroundTransparency = 0
local NameList = script.Parent.Plots:GetChildren()
for i=1,#NameList do
NameList[i] = tonumber(NameList[i].Name)
end
DataPoint.Name = math.max(unpack(NameList)) + 1
DataPoint.BackgroundColor3 = Color3.fromHSV((120 - ((script.Parent.Ping.Value / 200) * 120)) / 359, 1, 1)
if 120 - ((script.Parent.Ping.Value / 200) * 120) <= 0 then
DataPoint.BackgroundColor3 = Color3.fromHSV(0, 1, 1)
end
wait(0.016)
end
I know that having a script in each segment is, to put it lightly, extremely inefficient. I will be changing it to a singular script, though I will still be using the same method so I will still have this problem.
Lastly any help on how to optimize the method of drawing the segments or destroying them would be greatly appreciated.

4 comments
What you'd want to do is use a UIListLayout. This will automatically pair each GUI-Instance in a fashioned order depending on the layout you set it it. By adjusting it to horizontal, it should remove the need to perform heavy calculations on each bar to keep them next to each other.
To optimize your code, use RunService to call upon this code. Instead of using a while loop that will run regardless of your FPS, you can use the .RenderStepped signal to keep the code in sync with your computers capabilities, whilst looking smoother
@Feahren I don't know how I didn't think of any of that, thanks. Though it wouldn't order properly, since it will order it alphanumerically not numeric value. I would do base 64 but i'm making well over 64 instances. Also I don't think that will fix the issue at hand.
You’ll have to adjust the LayoutOrder through a Script for numerical ordering