TextButton is not positioned on MouseLocation

Hi, I am trying to make a TextButton that you can press and move with the mouse on the X axis.

But it does not seem to work well because it is not positioned correctly.

local isPressing = false

task.spawn(function()
	RunService.RenderStepped:Connect(function()
		if isPressing then
			local MouseLocation = UserInputService:GetMouseLocation()
			SettingsFrame.SizeBar.TextButton.Position = UDim2.new(0, math.clamp(MouseLocation.X, 0, 285), SettingsFrame.SizeBar.TextButton.Position.Y.Scale, 0)
		end
	end)
end)

SettingsFrame.SizeBar.TextButton.MouseButton1Down:Connect(function()
	isPressing = true
end)

SettingsFrame.SizeBar.TextButton.MouseButton1Up:Connect(function()
	isPressing = false
end)

If it’s not positioned well, then it’s an issue with the Position line. Can you show us a photo/video of it when you move it?


When I click on the TextButton this happens:

Check your math.clamp amounts, also keep in mind that mouse.X/Y return in offset, not scale.

local isPressing = false

RunService.RenderStepped:Connect(function()

if isPressing then

local MouseLocation = UserInputService:GetMouseLocation()

SettingsFrame.SizeBar.TextButton.Position = UDim2.new(0, math.clamp(0, game.Players.LocalPlayer:GetMouse().X, 0, 285), SettingsFrame.SizeBar.TextButton.Position.Y.Scale, 0)

end

end)

SettingsFrame.SizeBar.TextButton.MouseButton1Down:Connect(function()

isPressing = true

end)

SettingsFrame.SizeBar.TextButton.MouseButton1Up:Connect(function()

isPressing = false

end)

Try this. Idk… your code should be working…

Edit: Apparently clamp needs 3 numbers… my code is updated now

Is there another function for it to return in scale? Or is there another way to do it so that it is in scale?

Not that I know of. You can view the mouse API here