So I am making a game that requires a TextButton (Can be changed if needed, since there is no text) to be dragged. The problem is, I have no idea how to make it draggable on only one axis. I set it's Draggable property to true, but I can move it on both axes. How can I make it so it can move on one axis?
Would I use a while loop to keep the axis the same, or is there some sort of method? I'm not requesting a script, I just want to know some properties and methods that could accomplish this.
It's you're lucky day, this is what I just finished doing! I made it move in intervals, complicating the matter, but it's surprisingly easy(ish) to move a GUI on one axis.
I'd suggest not using the draggable property. I believe it is easier using MouseButton1Down and detecting when and how far the mouse is dragged using the Move event.
local mouse = game.Players.LocalPlayer:GetMouse() -- Need mouse for Move event local gui = script.Parent -- Location of GuiButton gui.MouseButton1Down:connect(function() local dragging = true -- Enable dragging mouse.Move:connect(function() if dragging then gui.Position = UDim2.new(0, mouse.X, 0, gui.Position.Y.Offset) -- Set the new position end end) mouse.Button1Up:connect(function() dragging = false -- Disable dragging end) gui.MouseButton1Up:connect(function() dragging = false -- Disable dragging end) end)
Only problem I'm having is that once mouse.Move
is called it will always be checking to see if the mouse is moving (hense the dragging variable). So if someone knows how to make Button1Up and MouseButton1Up stop mouse.Move
from running, I could make the transition from still to moving smoother. This still works, but if you know how to solve this problem leave a comment!