A problem for gui scripting

I get a problem about scripting the gui

I am scripting a drag frame but it work bad.

There is the script

  1. local MouseDown = false

  2. local UIS = game:GetService(“UserInputService”)

  3. local RunService = game:GetService(“RunService”)

  4. local CurrentBox = script.Parent

  5. UIS.InputBegan:Connect(function(input)

  6. if input.UserInputType == Enum.UserInputType.MouseButton1 then

  7.  MouseDown = true`Preformatted text`
    
  8. end

  9. end)

  10. UIS.InputEnded:Connect(function(input)

  11. if input.UserInputType == Enum.UserInputType.MouseButton1 then
    
  12. 	MouseDown = false
    
  13. end
    
  14. end)

  15. RunService.RenderStepped:Connect(function()

  16. if MouseDown then
    
  17. 	print(Mouse.x/1000)
    
  18. 	print(Mouse.y/1000)
    
  19. 	CurrentBox.Position = UDim2.new(Mouse.x/1000,0,Mouse.y/1000,0)
    
  20. end
    
  21. end)

Frame position is not same of the mouse on screen.



What is the purpose of dividing it with 1000? Why dont u just do this instead:

Udim2.new(mouse.X - gui.Size.fromOffset.X / 2, 0, mouse.Y + gui.Size.fromOffset.Y / 2, 0)

I dont know if I called all of the properties correctly like “fromOffset”, bc I havent script in a while