Getting mouse position inside plugin widget

I want to know if some stuff are possible when making a plugin, since im new to making plugins, i want to know if it’s possible to get a mouse position (UDim2) from inside the plugin widget, here is my idea to understand it further:

‘Icon Maker’


The plugin widget

My idea is to make a drawing area, where devs can draw what their icons should look like, and then simply click a ‘print’ to send the final result to ReplicatedStorage, but i forgot to test if it’s even possible to get the mouse position from inside the plugin widget.

I tried using plugin:GetMouse() but it only works on the 3D space, i used the script on the Plugin:GetMouse() documentation below
PluginMouse Documentation

plugin:Activate(false) -- gain non exclusive access to the mouse

local mouse = plugin:GetMouse()

local function button1Down()

print("Left mouse click")

end

mouse.Button1Down:Connect(button1Down)

I want to know if there is any way to get the position, since im a begginer at making plugins, i dont know what i could try

Edit: Here is some of the code for reference

--local TagS = game:GetService("CollectionService")
local Selection = game:GetService("Selection")
local toolbar = plugin:CreateToolbar("Image")
local newScriptButton = toolbar:CreateButton("Icon Maker", 
	"Make your own icon", 
	"rbxasset://studio_svg_textures/Shared/InsertableObjects/Dark/Standard/Decal@3x.png")
newScriptButton.ClickableWhenViewportHidden = true

local WindowContents = script.Parent.WidgetContent
local widgetInfo = DockWidgetPluginGuiInfo.new(
	Enum.InitialDockState.Float, -- Widget will be initialized in floating panel
	false, -- Widget will be initially enabled
	false, -- Don't override the previous enabled state
	800, -- Default width of the floating window
	800, -- Default height of the floating window
	600, -- Minimum width of the floating window (optional)
	600 -- Minimum height of the floating window (optional)
)


local testWidget = plugin:CreateDockWidgetPluginGui("IconMaker", widgetInfo)
local OpenW = testWidget.Enabled or false
--print(OpenW)
testWidget.Title = "Icon Maker"
WindowContents.Parent = testWidget



newScriptButton.Click:Connect(function()
	OpenW = not OpenW
	if OpenW then
		testWidget.Enabled = true
	else
		testWidget.Enabled = false
	end
end)



i tried using this too:

game:GetService("UserInputService").InputBegan:Connect(function(input)
	--print('input',input.UserInputType,input.KeyCode.Name)
	if input.UserInputType == Enum.UserInputType.MouseMovement then
		if OpenW then
			
			print("Test",CFrame.new(Vector3.new(input.Position.X,
				input.Position.Y, input.Position.Z) + Vector3.new(0,0,0)))
		end
	end
end)

And it also only works on the 3D workspace sadly

Nevermind, i found this gem of a code:

local function updateMousePosition(input)
	if input.UserInputType == Enum.UserInputType.MouseMovement then
		local relativePosition = Vector2.new(input.Position.X -testWidget.AbsolutePosition.X,
			input.Position.Y - testWidget.AbsolutePosition.Y)
		print("Mouse Position: (" .. math.floor(relativePosition.X) .. ", " .. 
			math.floor(relativePosition.Y) .. ")")
	end
end

-- Connect input events to update mouse position
WindowContents.InputChanged:Connect(updateMousePosition)

It perfectly prints what i need :smiley:

2 Likes

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.