Hello. I’m working on a Plugin. Long story short, I am trying to get the position of the mouse whenever you right-click on a widget, but the positions are relative to the 3D Viewport rather than the full window size.
If there is anyone who knows how to do that, please let me know!
Here is my current code:
local Players = game:GetService("Players")
local player = Players.LocalPlayer
local mouse = player:GetMouse()
local function createDropdownMenu()
if currentCoreDropdownMenu then currentCoreDropdownMenu:Destroy() currentCoreDropdownMenu = nil end
currentCoreDropdownMenu = script.Dropdown:Clone() -- Frame
currentCoreDropdownMenu.Parent = newWidget
currentCoreDropdownMenu.Position = UDim2.fromOffset(mouse.X, mouse.Y)
end
I have tried using UserInputService:GetMouseLocation(), but got the same results.
Sorry, what is the difference between LocalPlayer:GetMouse() and plugin:GetMouse()?
They both seem to be getting values relative to the 3D Viewport rather than the full window size.
I updated my code to this:
local mouse = plugin:GetMouse()
local function createDropdownMenu()
if currentCoreDropdownMenu then currentCoreDropdownMenu:Destroy() currentCoreDropdownMenu = nil end
currentCoreDropdownMenu = Instance.new("ScreenGui")
currentCoreDropdownMenu.IgnoreGuiInset = true
currentCoreDropdownMenu.DisplayOrder = 999999
currentCoreDropdownMenu.Parent = CoreGui
local frame = script.Dropdown:Clone()
frame.Parent = currentCoreDropdownMenu
print(mouse.X, mouse.Y) -- 0 Y value
frame.Position = UDim2.fromOffset(mouse.X, mouse.Y)
end
Since my widget is on the bottom left of your screen, whenever your mouse leaves the 3D viewport the X value becomes zero.
Then that means plugins cannot access the mouse if they’re not in the focus of their DockWidget or the Viewport. It might be a studio limitation or a security prevention
Then is there any way to get the absolute mouse position?
To give you more context, I am working on a chat plugin like Discord. Whenever you right-click on a message, a dropdown with some options (like Delete Message, Edit Message, Report Message etc.) should open.
All of that works, except the position. Is there any way you would be able to get the position of your mouse inside of a widget? That would be useful too.
Chat plugin? Message? That means you have your own UI, either in the Viewport or in a DockWidget? Why not simply use a button?
So you’re using PluginMouse, a DockWidget, but the location is still 0,0?