Get mouse position on button when UI button pressed

How would I get the mouse position on the button area to create a little effect when the player clicks the UI button. (like a little circle tweening outward and fading in transparency, starting at the click position on the button)

Thanks,

1 Like

You can use InputBegan/InputEnded on the button, I believe which would give you an InputObject of all the properties of the mouse.

That or you could use Mouse.X and Mouse.Y whenever they click the button.

local Mouse = game.Players.LocalPlayer:GetMouse()

button.MouseButton1Click:connect(function()
    print(Mouse.X, Mouse.Y)
end)
2 Likes

To get the position of the mouse relative to the button, use the mouse’s properties and the button’s absolute position to subtract the button’s position from the mouse’s position:

local RelativePosition = Vector2.new(Mouse.X,Mouse.Y)-Button.AbsolutePosition
13 Likes

oh ok! thanks my man!

3 Likes