Check if mouse position changed

Hello, I am trying to get the position of the mouse if the mouse has been moved!

More Detail: I am trying to make a script that will print the position of the players mouse on the X and Y, I searched up how to check if the properties have changed and it does not show what i am looking for.

Any help would be appreciated :slight_smile: Thank you

For mouse movement, use UserInputService.InputChanged.

local UserInputService = game:GetService("UserInputService")

UserInputService.InputChanged:Connect(function(input, engine_processed)
    if engine_processed then
        return
    end

    if input.UserInputType == Enum.UserInputType.MouseMovement then
        print("Mouse movement!")
    end
end)

You can use UserInputService::GetMouseLocation to get the 2D mouse coordinates. It returns a Vector2 describing this

local mouse_location = UserInputService:GetMouseLocation()
print(mouse_location.X, mouse_location.Y)
12 Likes

Thank you for the quick reply (i was surprised)

But anyways I will look over your script and implement changes to fit with what i was trying to accomplish!

:slight_smile: