Mobile gui slider position help

Hey, I have this code - it creates a draggable bar to customize player gravity.
It works as intended on computer, but on mobile when you drag and want to let go, it doesn’t let go and keeps following the players finger and I’m not sure how to fix it.

local l__Parent__1 = script.Parent;
local l__LocalPlayer__2 = game:GetService("Players").LocalPlayer;
local l__UserInputService__3 = game:GetService("UserInputService");
local l__RunService__4 = game:GetService("RunService");
function snap(p1, p2)
	if p2 == 0 then
		return p1;
	end;
	return math.floor(p1 / p2 + 0.5) * p2;
end;
local u1 = false;
l__UserInputService__3.InputEnded:connect(function(p3, p4)
	if p3.UserInputType == Enum.UserInputType.MouseButton1 then
		u1 = false;
	end;
end);
script.Parent.Button.TextButton.MouseButton1Down:Connect(function()
	u1 = true;
script.Parent.Button.TextButton.MouseButton1Up:Connect(function()
	u1 = false;
		
end)
end);
local l__Button__2 = l__Parent__1.Button;
local u3 = 0;
l__RunService__4.RenderStepped:connect(function(p5)
	if u1 then
		local l__Position__5 = l__Button__2.Position;
		u3 = math.clamp(snap((l__UserInputService__3:GetMouseLocation().X - l__Parent__1.AbsolutePosition.X) / l__Parent__1.AbsoluteSize.X, 0.01), 0, 1);
		l__Button__2.Position = UDim2.new(u3, 0, l__Position__5.Y.Scale, l__Position__5.Y.Offset);
	end;
end);

Can’t you just use a scrolling frame, which is a frame that includes a scroll bar.

You’ll probably have to try using specific mobile input connections to know when a mobile player stops touching the screen by using TouchEnded in the UserInputService. I won’t be able to help you much furthur if the issue gets more complicated because scripting mobile controls makes my skin itch still so… :cold_sweat:

What? I’m already using a scrolling frame to increase the amount of things I can put in the ui, but this is a slider button, to customise settings.

I’ve just fixed it with a input box, since it was the easiest option.

1 Like