I have been stuck on this topic for about an hour now and i have tried 3 different solutions, all of which have failed. I need to move a frame only on the Y axis to lock it in place there because i am making a slider GUI which uses the Scale property.
Just change the Y scale/offset components of the UDim2 value.
UDim2.new(scaleX, offsetX, scaleY, offsetY)
UDim2.new(0, 0, scaleY, offsetY) --change scaleY and offsetY only
I’m using the
Draggble property (i know it’s deprecated) so it needs to be only Y so the X is fine and can do whatever
You could maybe use a run service loop and have like ui.Position = udim2.new(0,ui.p.x,0,mouse.y)
I’m not sure how the Draggable property works, as I’ve never worked with it, but math.clamp might be of use?
You would use the RenderStepped function to always set the position X a fixed value and clamp the Y
local gui = script.Parent.Frame -- for example local axisToLock = "Y" local positionToLock = 0.5 local minPos = 50 local maxPos = 400 local runService = game:GetService("RunService") runService.RenderStepped:Connect(function() -- scale does not seem to work with this. so that's a reason why it's deprecated. -- to get the scale you would do this: currentPosition / maxPosition if axisToLock == "X" then local yPosition = gui.Position.Y local yOffset = math.clamp(yPosition.Offset, minPos, maxPos) gui.Position = UDim2.new(positionToLock, 0, 0, yOffset) else local xPosition = gui.Position.X local xOffset = math.clamp(xPosition.Offset, minPos, maxPos) gui.Position = UDim2.new(0, xOffset, positionToLock, 0) end end)