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);