local P=game:GetService("\085\115\101\114\073\110\112\117\116\083\101\114\118\105\099\101")local x=game:GetService("\071\117\105\083\101\114\118\105\099\101")local g={}g.__index=g function g.Connect(P,x,U,E)local s={}setmetatable(s,g)s.Connections={}s.Active=false if P and(x or U)then if E then table.insert(s.Connections,P.SelectionGained:Connect(function()s.Active=true if x then x()end end))table.insert(s.Connections,P.SelectionLost:Connect(function()s.Active=true if U then U()end end))end table.insert(s.Connections,P.InputBegan:Connect(function(P)if P.UserInputType==Enum.UserInputType.MouseMovement then s.Active=true if x then x()end end end))table.insert(s.Connections,P.InputEnded:Connect(function(P)if P.UserInputType==Enum.UserInputType.MouseMovement then s.Active=false if U then U()end end end))end return s end function g.Disconnect(P)if P and P.Connections then for x=1,#P.Connections,1 do local g=P.Connections[x]if g then g:Disconnect()end end end P=nil end return g


local UserInputService = game:GetService("UserInputService")
local GuiService = game:GetService("GuiService")

local Hover = {}
Hover.__index = Hover

	-- pass the element, and two functions (1=enter, 2=leave)
	function Hover.Connect(element,enter,leave, call_leave_on_selection_lost)
		local self = {}
		setmetatable(self,Hover)
		self.Connections = {}
		self.Active = false;
		if element and (enter or leave) then -- support both, or just one function (maybe we just want a sound to play on leave, etc)
			if call_leave_on_selection_lost then
				table.insert(self.Connections,
					element.SelectionGained:Connect(function()
						self.Active = true
						if enter then enter() end
					end)
				)
				table.insert(self.Connections,
					element.SelectionLost:Connect(function()
						self.Active = true
						if leave then leave() end
					end)
				)
			end
			table.insert(self.Connections,
				element.InputBegan:Connect(function(input)
					if input.UserInputType == Enum.UserInputType.MouseMovement then
						self.Active = true
						if enter then enter() end
					end
				end)
			)
			table.insert(self.Connections, 
				element.InputEnded:Connect(function(input)
					if input.UserInputType == Enum.UserInputType.MouseMovement then
						self.Active = false
						if leave then leave() end
					end
				end)
			)
		end
				
		return self
	end
		
	-- disconnects the events.
	function Hover:Disconnect()
		if self and self.Connections then
			for i=1,#self.Connections do
				local connection = self.Connections[i]
				if connection then connection:Disconnect() end
			end
		end
		self = nil
	end
	
	

return Hover