✓ Accepted answer
This is possible by using mouse.X and mouse.Y combined with mouse.ViewSizeY and mouse.ViewSizeX to determine the location on the screen. Though these can only be defined seperatly so it’s easiest to write a function for retrieving them when desired, instead of a mess of variables.
function GetMouse2D(Player)
if (game.Players[Player]) then
local Mouse = Player:GetMouse()
return Vector2.new(Mouse.X, Mouse.Y) / Vector2.new(Mouse.ViewSizeY, Mouse.ViewSizeX)
end
end
local UserInputService = game:GetService("UserInputService")
UserInputService.InputBegan:Connect(function(InputObject, GameProcessed)
if (InoutObject.UserInputType == Enum.UserInputType.MouseButton1) then
local MousePos = GetMouse2D()
print(MousePos)
end
end)
Hope this helps! If so, don’t forget to accept and upvote!
8 comments
That would work except for the fact that it would expand over the button and look weird. Im asking how to find the position of the mouse click relative to the button that the person clicked.
You’d fire this function inside the Click Listener. This would return the position presumably relative to the Button
With the code listed I dont think so? If I get just the position of the mouse and then parent it into a frame inside the button and position it to mouse.X and mouse.Y then it will be far off the screen.
Let me explain this a bit better. I want to position a ring to a frame which has the size of the button and it is parented to the button. I want the ring to be where you clicked on the button.
You’d use UserInputService or ContextActionService for this, then you can use ViewSize to get the normalized position
That should work?
How would I code that?
I’ve redone my answer as I said