How can I move my textbutton with Mouse.Move:Connect(function() inside the visible?

Well, I have a problem, and it is that the following script moves the position of the textbutton depending on the Y position of the mouse when pressing the textbutton, it does it itself but outside the limits UDim2.new (1, 0, 1, 0) and I don’t know how to solve it

local Players = game:GetService("Players")
local localPlayer = Players.LocalPlayer
local mouse = localPlayer:GetMouse()
local Button = script.Parent.TextButton

Button.MouseButton1Down:Connect(function()
mouse.Move:Connect(function(Y)
Button:TweenPosition(UDim2.new(0.5, 0, mouse.Y, 0))
end)
end)

Better use MouseMoved

local Button = script.Parent.TextButton
Button.MouseMoved:Connect(function(X, Y)
    Button:TweenPosition(UDim2.new(0.5, 0, 0, Y))
end)
1 Like

It works for me but it does not move at the same time as the mouse, causing it to go down a little and I have to go down more so that it goes down another little, it is as if it were stuck

so Mouse | Roblox Creator Documentation actually has how you would normalize the mouse position which is what your looking for

local Players = game:GetService("Players")
local localPlayer = Players.LocalPlayer
local mouse = localPlayer:GetMouse()
local Button = script.Parent.TextButton

Button.MouseButton1Down:Connect(function()
mouse.Move:Connect(function(Y)
Button:TweenPosition(UDim2.new(0.5, 0, mouse.Y/mouse.ViewSizeY, 0))
end)
end)

so how does this work for you

It also works for me but it is slow because if I stop moving the mouse, it stops moving towards the position it was moving and not the mouse because it is stuck a bit

local Players = game:GetService("Players")
local localPlayer = Players.LocalPlayer
local mouse = localPlayer:GetMouse()
local Button = script.Parent.TextButton

Button.MouseButton1Down:Connect(function()
mouse.Move:Connect(function(Y)
Button:TweenPosition(UDim2.new(0.5, 0, mouse.Y/mouse.ViewSizeY, 0), Enum.EasingDirection.Out,EasingStyle.Sine,.25,true)
end)
end)

my hope is that this should be less slow, tween position defults time to 1 second, and the override is optional I just think it would work in this circumstance