Hello there, I recently created a Graph Wiget for my game, so I can use it to map out some data. So far, this is what I have
The problem I’m facing right now is that I need a way of moving the points by clicking and dragging. I’ve tried to use the Plugin Mouse, UserInputService, and events, but I can’t get it to work. Does anyone know how I can create this feature?
Structure of the plugin:
Place File:
Gui tst.rbxl (39.9 KB)
Init Script:
local splineEditorBar = plugin:CreateToolbar("SplineToolsv3")
local splineEditor = splineEditorBar:CreateButton("SplineEditor", "SplineEditor", "rbxassetid://4458901886")
local status = false
splineEditor.ClickableWhenViewportHidden = true
local widgetInfo = DockWidgetPluginGuiInfo.new(
Enum.InitialDockState.Bottom, -- Widget will be initialized in floating panel
false, -- Widget will be initially enabled
false, -- Don't override the previous enabled state
200, -- Default width of the floating window
300, -- Default height of the floating window
150, -- Minimum width of the floating window
150 -- Minimum height of the floating window
)
local winWidget = plugin:CreateDockWidgetPluginGui("Graph", widgetInfo)
local MainF = script.Parent.GraphMain
MainF.Parent=winWidget
local function init()
if status then
winWidget.Enabled =false
status = false
else
winWidget.Enabled =true
status = true
end
end
splineEditor.Click:Connect(init)```
Graph Script:
local parent = script.Parent
local len = parent.Size.Width.Offset
local wid = parent.Size.Height.Offset
local image = "rbxssetid://1195495135"
local name = 1
local lastFrame = nil
local lastPoint = Instance.new("ImageButton")
local endPoint = Instance.new("ImageButton")
local function setUp()
lastPoint.Name = "StartPoint"
lastPoint.Image=image
lastPoint.Parent = parent
lastPoint.ZIndex = 2
lastPoint.Size = UDim2.new(0, 6, 0, 6)
lastPoint.Position = UDim2.new(0, 0, 0, 700)
lastPoint.AnchorPoint = Vector2.new(0.5, 0.5)
lastPoint:SetAttribute("Butons1",lastPoint.Name)
lastPoint.Parent = parent
endPoint.Name = "EndPoint"
endPoint.Image=image
endPoint.Parent = parent
endPoint.ZIndex = 2
endPoint.Size = UDim2.new(0, 6, 0, 6)
endPoint.Position = UDim2.new(0,1000, 0,0)
endPoint.AnchorPoint = Vector2.new(0.5, 0.5)
endPoint.Parent = parent
end
function drawPath(startBtn, endBtn)
local startX, startY = startBtn.Position.X.Offset, startBtn.Position.Y.Offset
local endX, endY = endBtn.Position.X.Offset, endBtn.Position.Y.Offset
local Line = Instance.new("Frame")
Line.AnchorPoint = Vector2.new(0.5, 0.5)
Line.Size = UDim2.new(0, ((endX - startX) ^ 2 + (endY - startY) ^ 2) ^ 0.5, 0, 5) -- Get the size using the distance formula
Line.Position = UDim2.new(0, (startX + endX) / 2, 0, (startY + endY) / 2) -- Get the position using the midpoint formula
Line.Rotation = math.atan2(endY - startY, endX - startX) * (180 / math.pi) -- Get the rotation using atan2, convert radians to degrees
Line.Parent = parent
return Line
end
local function placePoint(pos)
local butin = Instance.new("ImageButton")
butin.Parent = parent
butin.Image=image
butin.Parent = parent
butin.ZIndex = 2
butin.Size = UDim2.new(0, 6, 0, 6)
butin.Position = pos
butin.AnchorPoint = Vector2.new(0.5, 0.5)
butin.Name = butin.Name..tostring(name)
return butin
end
local function Point(input)
local J = parent.AbsolutePosition.X
local b = parent.AbsolutePosition.Y
local btn = placePoint(UDim2.new(0, input.Position.X-J, 0, input.Position.Y-b))
drawPath(lastPoint,btn)
if lastFrame == nil then
lastFrame = drawPath(btn,endPoint)
btn:SetAttribute("Butons1",lastPoint.Name)
btn:SetAttribute("Butons2",endPoint.Name)
lastPoint:SetAttribute("Butons2",btn.Name)
else
lastFrame:Destroy()
lastFrame = drawPath(btn,endPoint)
btn:SetAttribute("Butons1",lastPoint.Name)
btn:SetAttribute("Butons2",endPoint.Name)
lastPoint:SetAttribute("Butons2",btn.Name)
end
lastPoint = btn
end
local function DetectInput(input)
if input.UserInputType == Enum.UserInputType.MouseButton1 then
Point(input)
end
end
setUp()
parent.InputBegan:Connect(DetectInput)