I second this. Implementing dragging I’ve found to be pretty simple (I’ll take a spelling check because I haven’t looked at the wiki, but if you remember if it’s -ed or -ing off the top of your head, good for you):
local Frame
local DragConnection
local function Drag()
-- constrain position to acceptable ranges
local P = UDim2.new(0,math.max(MinXPosition,math.min(MaxXPosition,Frame.Position.X.Offset)),0,math.max(MinXPosition,math.min(MaxYPosition,Frame.Position.Y.Offset))
-- apply position to Frame
Frame.Position = P
FrameJustGotDragged(P.Position.X.Offset-MinXPosition,P.Position.Y.Offset-MinYPosition) -- send the new input to wherever it's needed
end
local function DragBegin()
DragConnection = Frame.Changed:connect(Drag)
end
local function DragEnded()
if DragConnection then
DragConnection:disconnect()
end
end
Frame.DragBegin:connect(DragBegin)
Frame.DragEnded:connect(DragEnded)
This is simpler for sliders because one component is hard-coded, either the X component for vertical sliders or the Y component for horizontal sliders.
EDIT:
Here is a code block from an actual project:
ReverserHandleDragger.DragBegin:connect(function()
local dragged = ReverserHandleDragger.Changed:connect(function() -- anonymous function to constrain frame, calculate input, and pass it on up
if not ReverserLocked then
local px = ReverserHandleDragger.Position.X.Offset -- this is a horizontal slider
if px > 40 then -- over the max
px = 40 -- set px to max
ReverserHandleDragger.Position = UDim2.new(0,px,0,0)
elseif px < -10 then -- under the min
px = -10 -- set px to min
ReverserHandleDragger.Position = UDim2.new(0,px,0,0)
elseif ReverserHandleDragger.Position.Y.Offset ~= 0 then
ReverserHandleDragger.Position = UDim2.new(0,px,0,0) -- I probably could have moved this line out of the if block but whatever
end
local intermidiatesetting = (px-15)/25 -- alpha from -1 to 1
if intermidiatesetting < -.333 then
ReverserSetting =-1 -- put the train in reverse
ThrottleLocked = false -- unlock the throttle
elseif intermidiatesetting > .333 then
ReverserSetting = 1 -- put the train in forward
ThrottleLocked = false -- unlock the throttle
else
ReverserSetting = 0 -- put the train in neutral
ThrottleLocked = true -- lock the throttle
end
if ReverserSetting ~= PreviousReverserSetting then
remote:FireServer({["Reverser"]=ReverserSetting}) -- tell the server what we are doing
end
PreviousReverserSetting = ReverserSetting -- look for changes in the future
ConfigureReverserHandle() -- update the GUI
else
ReverserHandleDragger.Position = UDim2.new(0,ReverserSetting*25+15,0,0) -- locked in place
end
end)
local dragstop = nil
dragstop = ReverserHandleDragger.DragStopped:connect(function() -- clean up after yourself
ForceReverserHandle()
dragged:disconnect()
dragstop:disconnect()
end)
end)
As far as snapping, CmdUtl 5.0.0 has this, and I’m pretty sure SBS has it too. I’ve done it as well, but I’m not about to go deep diving to find it.
I’m missing why “snapping or constraints cannot be implemented” and am still questioning why it was deprecated. I have never had any outstanding issues with it.