Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
2

How to Fix Line Graph Generating Script? [closed]

Asked by
Benbebop 1049 Moderation Voter
4 years ago
Edited 4 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:

local TweenService = game:GetService("TweenService")
local LastPlot = Vector2.new(0,0)

script.Parent.Ping.Changed:Connect(function()
    local CurrentPlot = Vector2.new(1, 1 - (script.Parent.Ping.Value / 500))
    local DataPoint = script.LineSegment:Clone()
    DataPoint.Position = UDim2.new(1, 0, 1 - (script.Parent.Ping.Value / 500), 0)
    DataPoint.Parent = script.Parent.Plots

    local LineSegment = script.LineSegment:Clone()
    LineSegment.AnchorPoint = Vector2.new(0,0)
    LineSegment.Position = UDim2.new(LastPlot.X, 0, LastPlot.Y, 0)
    LineSegment.Size = UDim2.new((CurrentPlot - LastPlot).Magnitude, 0, 0, 1)
    LineSegment.Rotation = 180/math.pi*math.atan((CurrentPlot.Y - LastPlot.Y)/(CurrentPlot.X - LastPlot.X))
    LineSegment.Parent = script.Parent.Plots
    local LastPlot = Vector2.new(DataPoint.Position.X.Scale, DataPoint.Position.Y.Scale)

    local goal = {}
    goal.Position = UDim2.new(0, 0, 1 - (script.Parent.Ping.Value / 500), 0)
    local tweenInfo = TweenInfo.new(script.Parent.Speed.Value, 0)
    local tween1 = TweenService:Create(DataPoint, tweenInfo, goal)
    local tween2 = TweenService:Create(LineSegment, tweenInfo, goal)
    tween1:Play()
    tween2:Play()
    wait(script.Parent.Speed.Value)
    DataPoint:Destroy()
    wait()
    DataPoint:Destroy()
end)

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

0
Maybe get rid of the inner set of parenthesis? If you just have one for the udim thing, it may work, but that is all I can think of since I am not good at this sort of stuff. Phyrixia 51 — 4y
0
@Phyrixia I already found a solution for this awhile ago, thanks none the less. Benbebop 1049 — 4y

Locked by Leamir

This question has been locked to preserve its current state and prevent spam and unwanted comments and answers.

Why was this question closed?