How to detect mouse position inside a Frame?

As the title says, I’ve been trying to find a way to detect my mouse’s position inside a Frame.
For example when player clicks in the Frame it would print the position inside the frame where the player clicked.

The problem is, I have no idea how to do this and if anyone could drop any hints for me that would be very helpful and appreciated!


All you need to do is check when the frame is clicked on and then subtract the mouse’s position by the frame’s absolute position.

local frame = FRAME

local function inputBegan(input)
    if input.UserInputType == Enum.UserInputType.MouseButton1 then
        local position = input.Position - frame.AbsolutePosition
        --do stuff with it


One way to see where the mouse is inside of a Frame is using the MouseMoved event.

This doesn’t handle the clicking aspect of it for a frame, but the code @KingOfHungry provided does capture the click.

1 Like

(Mouse.X - Frame.AbsolutePosition.X)

You just subtract the mouse x value from the frames aboluteposition x value. Same with Y.

@KingOfHungry wrote the code above


Thank you for the replies, they made me figure out what I wanted to do!
Wish I could mark all 3 as the solutions :slight_smile:

1 Like