Detecting Mouse Input (PLUGIN)

Basically I’m working on a plugin to zoom in on UI objects (or im trying to) and I seen to be experiencing some draw backs with what I’m doing.

I’m currently using the PluginMouse but before I was using UserInputService but that didn’t exactly work as planned so I ditched it and just used it for checking if they are holding Ctrl while scrolling, now my current issue is It triggers the mouse moved function (isn’t exactly relevant to my plugin but currently used for debugging purposes)

when selecting any instance it works perfectly fine but if you select the StarterGui or anything inside of that it just doesn’t trigger those events, Now you might be seeing where my issue starts to come into play. I’m going to be using the plugin literally when you have a UI object selected as thats how it will detect what to zoom into except I don’t really know any work around for this. If I can get some assistance with this that would be greatly appreciated.

F3Ush77XEO

Current code

local Connections = {}
local UserInputService = game:GetService("UserInputService")
plugin:Activate(false)
local PluginMouse = plugin:GetMouse()

local function LoadSystem()
	warn("Loaded")
	
	Connections["SelectionChange"] = game:GetService("Selection").SelectionChanged:Connect(function()
		plugin:Activate(false)
	end)
	
	Connections["MouseWheelUp"] = PluginMouse.WheelForward:Connect(function()
		if UserInputService:IsKeyDown(Enum.KeyCode.LeftControl) then
			local Succ, Error = pcall(function()
				warn("up_")
				local ActiveSelection = game:GetService("Selection"):Get()
				local ZoomOnScreenUI = nil

				for _, IsScreen in pairs(ActiveSelection) do
					if ZoomOnScreenUI == nil then
						ZoomOnScreenUI = IsScreen:FindFirstAncestorOfClass("ScreenGui")
					end
				end

				warn("UP", ZoomOnScreenUI.Name)		
			end)

			if not Succ then
				warn(Error)
			end
		end
	end)
	
	Connections["MouseWheelDown"] = PluginMouse.WheelBackward:Connect(function()
		if UserInputService:IsKeyDown(Enum.KeyCode.LeftControl) then
			local Succ, Error = pcall(function()
				warn("down_")
				local ActiveSelection = game:GetService("Selection"):Get()
				local ZoomOnScreenUI = nil

				for _, IsScreen in pairs(ActiveSelection) do
					if ZoomOnScreenUI == nil then
						ZoomOnScreenUI = IsScreen:FindFirstAncestorOfClass("ScreenGui")
					end
				end

				warn("DOWN", ZoomOnScreenUI.Name)				
			end)
			
			if not Succ then
				warn(Error)
			else
				print("succ")
			end
		end
	end)
	
	Connections["MouseMoved"] = PluginMouse.Move:Connect(function()
		print("Moved")
	end)
end

local function UnloadSystem()
	warn("Unloading plugin lol")
	for _, UnloadConnection in pairs(Connections) do
		UnloadConnection:Disconnect()
	end
end

LoadSystem()

plugin.Unloading:Connect(function()
	UnloadSystem()
end)

I had this problem before too! Let me see what I ended up doing…

I actually ended up figuring it out with UserInputService, I was using InputBegan instead of InputChanged fixing my issue.

qwtVPAfeho

Connections["Input"] = UserInputService.InputChanged:Connect(function(Input, IsGame)
		if IsGame == false and Input.UserInputType == Enum.UserInputType.MouseWheel then
			local IsUp = Input.Position.Z > 0
			local ActiveSelection = game:GetService("Selection"):Get()
			local ZoomOnScreenUI = nil			
			
			local Succ, Error = pcall(function()
				for _, IsScreen in pairs(ActiveSelection) do
					if ZoomOnScreenUI == nil then
						ZoomOnScreenUI = IsScreen:FindFirstAncestorOfClass("ScreenGui") or if IsScreen:IsA("ScreenGui") then IsScreen else nil
					end
				end
			end)

			if not Succ then
				warn(Error)
			else
				if ZoomOnScreenUI ~= nil or game then
					if IsUp then
						if UserInputService:IsKeyDown(Enum.KeyCode.LeftControl) and not UserInputService:IsKeyDown(Enum.KeyCode.LeftShift) then
							-- Scroll Up
							warn("Scroll Up")
						elseif UserInputService:IsKeyDown(Enum.KeyCode.LeftShift) and not UserInputService:IsKeyDown(Enum.KeyCode.LeftControl) then
							-- Pan Left
							warn("Pan Left")
						end
					else
						if UserInputService:IsKeyDown(Enum.KeyCode.LeftControl) and not UserInputService:IsKeyDown(Enum.KeyCode.LeftShift) then
							-- Scroll Down
							warn("Scroll Down")
						elseif UserInputService:IsKeyDown(Enum.KeyCode.LeftShift) and not UserInputService:IsKeyDown(Enum.KeyCode.LeftControl) then
							-- Pan Right
							warn("Pan Right")
						end
					end
				end
			end
		end
	end)