How to Fix Line Graph Generating Script? [closed]
Asked by
5 years ago Edited 5 years ago
I made a script that gets ping, now I want to make a line graph that shows that information. But the lines do not match up at all with the plots.
Heres the script:
01 | local TweenService = game:GetService( "TweenService" ) |
02 | local LastPlot = Vector 2. new( 0 , 0 ) |
04 | script.Parent.Ping.Changed:Connect( function () |
05 | local CurrentPlot = Vector 2. new( 1 , 1 - (script.Parent.Ping.Value / 500 )) |
06 | local DataPoint = script.LineSegment:Clone() |
07 | DataPoint.Position = UDim 2. new( 1 , 0 , 1 - (script.Parent.Ping.Value / 500 ), 0 ) |
08 | DataPoint.Parent = script.Parent.Plots |
10 | local LineSegment = script.LineSegment:Clone() |
11 | LineSegment.AnchorPoint = Vector 2. new( 0 , 0 ) |
12 | LineSegment.Position = UDim 2. new(LastPlot.X, 0 , LastPlot.Y, 0 ) |
13 | LineSegment.Size = UDim 2. new((CurrentPlot - LastPlot).Magnitude, 0 , 0 , 1 ) |
14 | LineSegment.Rotation = 180 /math.pi*math.atan((CurrentPlot.Y - LastPlot.Y)/(CurrentPlot.X - LastPlot.X)) |
15 | LineSegment.Parent = script.Parent.Plots |
16 | local LastPlot = Vector 2. new(DataPoint.Position.X.Scale, DataPoint.Position.Y.Scale) |
19 | goal.Position = UDim 2. new( 0 , 0 , 1 - (script.Parent.Ping.Value / 500 ), 0 ) |
20 | local tweenInfo = TweenInfo.new(script.Parent.Speed.Value, 0 ) |
21 | local tween 1 = TweenService:Create(DataPoint, tweenInfo, goal) |
22 | local tween 2 = TweenService:Create(LineSegment, tweenInfo, goal) |
25 | wait(script.Parent.Speed.Value) |
Sorry if this is a mess you only need to worry about lines 11-16
Defiantly a problem with my equation on line 13 but I'm not sure what I did wrong.
(CurrentPlot - LastPlot).Magnitude
Here im trying to get the distance (In scale not offset) between the two Vector2s.
Here is the Explorer
Here is the Results
I know there is a problem with the tweening and destroying but I can fix that myself