How to detect when the mouse is hovering over a GUI? (Roblox built-in UI included)

Hello fellow developers! I am currently creating an input detection system (mainly for m1 combat) and I need to be able to detect when the mouse hovers over any gui, roblox UI included, so i can stop the “hold” event. Here is my code:

local ReplicatedStorage = game:GetService("ReplicatedStorage")
local InputR = ReplicatedStorage.Remotes.Input
local player = game.Players.LocalPlayer
local InputService = game:GetService("UserInputService")
local camera = game.Workspace.CurrentCamera
local CAS = game:GetService("ContextActionService")



local inputs = {
	[Enum.UserInputType.MouseButton1] = {
		["SkillName"] = "M1";
	}
}

local function sendtoServer(key,...)
		local args = {key, ...}
		InputR:FireServer(
			args
			)
end
local hold = nil
for i,v in inputs do
	CAS:BindAction(v.SkillName,function(_,inputObj,_)
		if inputObj == Enum.UserInputState.Begin then
			if i == Enum.UserInputType.MouseButton1 then
				hold = game["Run Service"].RenderStepped:Connect(function()
					sendtoServer(v, {
						"test"
					})
				end)
			
			end
		elseif inputObj == Enum.UserInputState.End then
			if i == Enum.UserInputType.MouseButton1 then
				if hold then
					hold:Disconnect()
					hold = nil
				end
			end
		end
		return Enum.ContextActionResult.Pass
	end, false, i)
		
end



If anyone needs further explanation on what I am requiring, just let me know.

This is the reason I need this: Gyazo video

When the output prints “Combat working”, that is when im holding the mouse. When it stops, is when I stop.
However, when I hold the mouse, then hover over a Roblox topbar element (may do this with other UI’s too, not sure) and let go, the “Combat working” keeps printing, even though i am not holding the mouse.
I need this system so I can detect when the player is hovering over one of these UI’s while holding MB1 and to stop the event when they are doing so, and resume it when they move their mouse off of it and still are holding MB1.
Thanks!

Did you check if the InputObj.Position.X < 0 and InputObj.Position.Y is less than 0?