local o=false function IconController.updateTopbar()local function a(o,a)local x=o:get("\105\099\111\110\083\105\122\101",o:getIconState())or UDim2.new(0,32,0,32)local r=x.X.Offset local f=IconController[a.."\071\097\112"]local Y=r+f local l=Y local u=0 if o._parentIcon==nil then local a,x,r=IconController.getMenuOffset(o)u+=a l+=x+r end return l,u end if topbarUpdating then o=true return false end;(coroutine.wrap(function()topbarUpdating=true runService.Heartbeat:Wait()topbarUpdating=false for o,a in pairs(alignmentDetails)do a.records={}end for o,a in pairs(topbarIcons)do if IconController.canShowIconOnTopbar(o)then local a=o:get("\097\108\105\103\110\109\101\110\116")table.insert(alignmentDetails[a].records,o)end end local x=workspace.CurrentCamera.ViewportSize for o,r in pairs(alignmentDetails)do local f=r.records if#f>1 then if r.reverseSort then table.sort(f,function(o,a)return o:get("\111\114\100\101\114")>a:get("\111\114\100\101\114")end)else table.sort(f,function(o,a)return o:get("\111\114\100\101\114")<a:get("\111\114\100\101\114")end)end end local Y=0 for x,r in pairs(f)do local f=a(r,o)Y=Y+f end local l=r.getStartOffset(Y,o)local u=l local v=TopbarPlusGui.TopbarContainer.AbsoluteSize.X for x,f in pairs(f)do local Y,l=a(f,o)local e=(r.startScale*v+u)+l u=u+Y end for f,Y in pairs(f)do local u=Y.instances.iconContainer local v,e=a(Y,o)local P=Y.topPadding local J=UDim2.new(r.startScale,l+e,P.Scale,P.Offset)local T=string.match(Y.name,"\095\111\118\101\114\102\108\111\119\073\099\111\110-")local p=Y:get("\114\101\112\111\115\105\116\105\111\110\073\110\102\111")if p then(tweenService:Create(u,p,{Position=J})):Play()else u.Position=J end l=l+v Y.targetPosition=UDim2.new(0,J.X.Scale*x.X+J.X.Offset,0,J.Y.Scale*x.Y+J.Y.Offset)end end local r=10 local function f(o,a,x)local r=x or 0 local f=o:get("\105\099\111\110\083\105\122\101",o:getIconState())local Y=f.X.Offset local l,u=IconController.getMenuOffset(o)local v=a=="\108\101\102\116"and-r-l or a=="\114\105\103\104\116"and(Y+r)+u local e=o.targetPosition.X.Offset+v return e end local function Y(o,a)local x,r=o:get("\105\099\111\110\083\105\122\101",o:getIconState(),"\098\101\102\111\114\101\068\114\111\112\100\111\119\110")local f=a and r or x local Y,l=IconController.getMenuOffset(o)local u=(f.X.Offset+Y)+l return u end for o,a in pairs(alignmentDetails)do local l=a.overflowIcon if l then local u=IconController[o.."\071\097\112"]local v=o=="\108\101\102\116"and"\114\105\103\104\116"or"\108\101\102\116"local e=alignmentDetails[v]local P=IconController.getIcon("\095\111\118\101\114\102\108\111\119\073\099\111\110-"..v)local J=f(l,o)if l.enabled then J=f(l,v,u)end local function T(a)local x=o=="\108\101\102\116"and a<J or o=="\114\105\103\104\116"and a>J return x end local p=e.getOffset()if not l.enabled then p+=r end local z=o=="\108\101\102\116"and x.X-p or o=="\114\105\103\104\116"and p local j=z local h=T(j)local function N(a)local x=#a for Y=1,x,1 do local u=a[(x+1)-Y]if IconController.canShowIconOnTopbar(u)then local a=string.match(u.name,"\095\111\118\101\114\102\108\111\119\073\099\111\110-")if a and x~=1 then break elseif a and not u.enabled then continue end local Y=0 if not l.enabled then Y=r end local v=f(u,o,Y)local e=o=="\108\101\102\116"and v<j or o=="\114\105\103\104\116"and v>j if e then j=v if T(v)then h=true end end end end end N(alignmentDetails[v].records)N(alignmentDetails.mid.records)if h then local x=a.records local r=#x for a=1,r,1 do local Y=o=="\108\101\102\116"and x[(r+1)-a]or o=="\114\105\103\104\116"and x[a]if Y~=l and IconController.canShowIconOnTopbar(Y)then local a=u local x=(l:get("\105\099\111\110\083\105\122\101",l:getIconState())).X.Offset if l.enabled then a+=u+x end local r=f(Y,v,a)local e=o=="\108\101\102\116"and r>=j or o=="\114\105\103\104\116"and r<=j if e then if not l.enabled then local a=l.instances.iconContainer local x=a.Position.Y local r=o=="\108\101\102\116"and-a.Size.X.Offset or 0 local u=f(Y,v,r)a.Position=UDim2.new(0,u,x.Scale,x.Offset)l:setEnabled(true)end if#Y.dropdownIcons>0 then Y._overflowConvertedToMenu=true local o=Y.isSelected Y:deselect()local a={}for o,x in pairs(Y.dropdownIcons)do table.insert(a,x)end for o,a in pairs(Y.dropdownIcons)do a:leave()end Y:setMenu(a)if o and l.isSelected then Y:select()end end Y:join(l,"\100\114\111\112\100\111\119\110")if#Y.menuIcons>0 and Y.menuOpen then Y:deselect()Y:select()l:select()end end break end end else local x,J local T=#l.dropdownIcons if not(P and(P.enabled and(#a.records==1 and#e.records~=1)))then for a,r in pairs(l.dropdownIcons)do local f=r:get("\111\114\100\101\114")if J==nil or o=="\108\101\102\116"and f<x or o=="\114\105\103\104\116"and f>x then x=f J=r end end end if J then local a=Y(J,true)local x=f(l,v)if T==1 then x=f(l,o,u-r)end local e=math.abs(j-x)-u*2 local P=a<e if P then if#l.dropdownIcons==1 then l:setEnabled(false)end local o=l.instances.iconContainer local a=o.Position.Y o.Position=UDim2.new(0,x,a.Scale,a.Offset)J:leave()if J._overflowConvertedToMenu then J._overflowConvertedToMenu=nil local o={}for a,x in pairs(J.menuIcons)do table.insert(o,x)end for o,a in pairs(J.menuIcons)do a:leave()end J:setDropdown(o)end end end end end end if o then o=false IconController.updateTopbar()end return true end))()end function IconController.setTopbarEnabled(o,a)if a==nil then a=true end local x=TopbarPlusGui.Indicator if a and not o then forceTopbarDisabled=true elseif a and o then forceTopbarDisabled=false end if IconController.controllerModeEnabled then if o then if TopbarPlusGui.TopbarContainer.Visible or forceTopbarDisabled or menuOpen or not checkTopbarEnabled()then return end if a then x.Visible=checkTopbarEnabled()else if hapticService:IsVibrationSupported(Enum.UserInputType.Gamepad1)and hapticService:IsMotorSupported(Enum.UserInputType.Gamepad1,Enum.VibrationMotor.Small)then hapticService:SetMotor(Enum.UserInputType.Gamepad1,Enum.VibrationMotor.Small,1)delay(.2,function()pcall(function()hapticService:SetMotor(Enum.UserInputType.Gamepad1,Enum.VibrationMotor.Small,0)end)end)end TopbarPlusGui.TopbarContainer.Visible=true TopbarPlusGui.TopbarContainer:TweenPosition(UDim2.new(0,0,0,5+STUPID_CONTROLLER_OFFSET),Enum.EasingDirection.Out,Enum.EasingStyle.Quad,.1,true)local o local a=0 IconController:_updateSelectionGroup()runService.Heartbeat:Wait()local r=50 for x,f in pairs(topbarIcons)do if IconController.canShowIconOnTopbar(x)and(o==nil or x:get("\111\114\100\101\114")>o:get("\111\114\100\101\114"))then o=x end local Y=x.instances.iconContainer local l=(-27+Y.AbsoluteSize.Y)+r if l>a then a=l end end if guiService:GetEmotesMenuOpen()then guiService:SetEmotesMenuOpen(false)end if guiService:GetInspectMenuEnabled()then guiService:CloseInspectMenu()end local f=IconController._previousSelectedObject or o.instances.iconButton IconController._setControllerSelectedObject(f)x.Image="\114\098\120\097\115\115\101\116\105\100\058\047\047\053\050\055\056\049\053\049\048\055\049"x:TweenPosition(UDim2.new(.5,0,0,a+STUPID_CONTROLLER_OFFSET),Enum.EasingDirection.Out,Enum.EasingStyle.Quad,.1,true)end else if a then x.Visible=false else x.Visible=checkTopbarEnabled()end if not TopbarPlusGui.TopbarContainer.Visible then return end guiService.AutoSelectGuiEnabled=true IconController:_updateSelectionGroup(true)TopbarPlusGui.TopbarContainer:TweenPosition(UDim2.new(0,0,0,-TopbarPlusGui.TopbarContainer.Size.Y.Offset+STUPID_CONTROLLER_OFFSET),Enum.EasingDirection.Out,Enum.EasingStyle.Quad,.1,true,function()TopbarPlusGui.TopbarContainer.Visible=false end)x.Image="\114\098\120\097\115\115\101\116\105\100\058\047\047\053\050\055\056\049\053\049\053\053\054"x:TweenPosition(UDim2.new(.5,0,0,5),Enum.EasingDirection.Out,Enum.EasingStyle.Quad,.1,true)end else local a=TopbarPlusGui.TopbarContainer if checkTopbarEnabled()then a.Visible=o else a.Visible=false end end end function IconController.setGap(o,a)local x=tonumber(o)or 12 local r=(tostring(a)):lower()if r=="\108\101\102\116"or r=="\109\105\100"or r=="\114\105\103\104\116"then IconController[r.."\071\097\112"]=x return end IconController.leftGap=x IconController.midGap=x IconController.rightGap=x IconController.updateTopbar()end local a=players.LocalPlayer local x={}a.CharacterAdded:Connect(function()for o,a in pairs(x)do a:destroy()end x={}end)function IconController.clearIconOnSpawn(o)(coroutine.wrap(function()local r=a.Character or a.CharacterAdded:Wait()table.insert(x,o)end))()end

local requestedTopbarUpdate = false
function IconController.updateTopbar()
	local function getIncrement(otherIcon, alignment)
		--local container = otherIcon.instances.iconContainer
		--local sizeX = container.Size.X.Offset
		local iconSize = otherIcon:get("iconSize", otherIcon:getIconState()) or UDim2.new(0, 32, 0, 32)
		local sizeX = iconSize.X.Offset
		local alignmentGap = IconController[alignment.."Gap"]
		local iconWidthAndGap = (sizeX + alignmentGap)
		local increment = iconWidthAndGap
		local preOffset = 0
		if otherIcon._parentIcon == nil then
			local extendLeft, extendRight, additionalRight = IconController.getMenuOffset(otherIcon)
			preOffset += extendLeft
			increment += extendRight + additionalRight
		end
		return increment, preOffset
	end
	if topbarUpdating then -- This prevents the topbar updating and shifting icons more than it needs to
		requestedTopbarUpdate = true
		return false
	end
	coroutine.wrap(function()
		topbarUpdating = true
		runService.Heartbeat:Wait()
		topbarUpdating = false
		
		for alignment, alignmentInfo in pairs(alignmentDetails) do
			alignmentInfo.records = {}
		end

		for otherIcon, _ in pairs(topbarIcons) do
			if IconController.canShowIconOnTopbar(otherIcon) then
				local alignment = otherIcon:get("alignment")
				table.insert(alignmentDetails[alignment].records, otherIcon)
			end
		end
		local viewportSize = workspace.CurrentCamera.ViewportSize
		for alignment, alignmentInfo in pairs(alignmentDetails) do
			local records = alignmentInfo.records
			if #records > 1 then
				if alignmentInfo.reverseSort then
					table.sort(records, function(a,b) return a:get("order") > b:get("order") end)
				else
					table.sort(records, function(a,b) return a:get("order") < b:get("order") end)
				end
			end
			local totalIconX = 0
			for i, otherIcon in pairs(records) do
				local increment = getIncrement(otherIcon, alignment)
				totalIconX = totalIconX + increment
			end
			local offsetX = alignmentInfo.getStartOffset(totalIconX, alignment)
			local preOffsetX = offsetX
			local containerX = TopbarPlusGui.TopbarContainer.AbsoluteSize.X
			for i, otherIcon in pairs(records) do
				local increment, preOffset = getIncrement(otherIcon, alignment)
				local newAbsoluteX = alignmentInfo.startScale*containerX + preOffsetX+preOffset
				preOffsetX = preOffsetX + increment
			end
			for i, otherIcon in pairs(records) do
				local container = otherIcon.instances.iconContainer
				local increment, preOffset = getIncrement(otherIcon, alignment)
				local topPadding = otherIcon.topPadding
				local newPositon = UDim2.new(alignmentInfo.startScale, offsetX+preOffset, topPadding.Scale, topPadding.Offset)
				local isAnOverflowIcon = string.match(otherIcon.name, "_overflowIcon-")
				local repositionInfo = otherIcon:get("repositionInfo")
				if repositionInfo then
					tweenService:Create(container, repositionInfo, {Position = newPositon}):Play()
				else
					container.Position = newPositon
				end
				offsetX = offsetX + increment
				otherIcon.targetPosition = UDim2.new(0, (newPositon.X.Scale*viewportSize.X) + newPositon.X.Offset, 0, (newPositon.Y.Scale*viewportSize.Y) + newPositon.Y.Offset)
			end
		end

		-- OVERFLOW HANDLER
		--------
		local START_LEEWAY = 10 -- The additional offset where the end icon will be converted to ... without an apparant change in position
		local function getBoundaryX(iconToCheck, side, gap)
			local additionalGap = gap or 0
			local currentSize = iconToCheck:get("iconSize", iconToCheck:getIconState())
			local sizeX = currentSize.X.Offset
			local extendLeft, extendRight = IconController.getMenuOffset(iconToCheck)
			local boundaryXOffset = (side == "left" and (-additionalGap-extendLeft)) or (side == "right" and sizeX+additionalGap+extendRight)
			local boundaryX = iconToCheck.targetPosition.X.Offset + boundaryXOffset
			return boundaryX
		end
		local function getSizeX(iconToCheck, usePrevious)
			local currentSize, previousSize = iconToCheck:get("iconSize", iconToCheck:getIconState(), "beforeDropdown")
			local newSize = (usePrevious and previousSize) or currentSize
			local extendLeft, extendRight = IconController.getMenuOffset(iconToCheck)
			local sizeX = newSize.X.Offset + extendLeft + extendRight
			return sizeX
		end

		for alignment, alignmentInfo in pairs(alignmentDetails) do
			local overflowIcon = alignmentInfo.overflowIcon
			if overflowIcon then
				local alignmentGap = IconController[alignment.."Gap"]
				local oppositeAlignment = (alignment == "left" and "right") or "left"
				local oppositeAlignmentInfo = alignmentDetails[oppositeAlignment]
				local oppositeOverflowIcon = IconController.getIcon("_overflowIcon-"..oppositeAlignment)
				
				-- This determines whether any icons (from opposite or mid alignment) are overlapping with this alignment
				local overflowBoundaryX = getBoundaryX(overflowIcon, alignment)
				if overflowIcon.enabled then
					overflowBoundaryX = getBoundaryX(overflowIcon, oppositeAlignment, alignmentGap)
				end
				local function doesExceed(givenBoundaryX)
					local exceeds = (alignment == "left" and givenBoundaryX < overflowBoundaryX) or (alignment == "right" and givenBoundaryX > overflowBoundaryX)
					return exceeds
				end
				local alignmentOffset = oppositeAlignmentInfo.getOffset()
				if not overflowIcon.enabled then
					alignmentOffset += START_LEEWAY
				end
				local alignmentBorderX = (alignment == "left" and viewportSize.X - alignmentOffset) or (alignment == "right" and alignmentOffset)
				local closestBoundaryX = alignmentBorderX
				local exceededCriticalBoundary = doesExceed(closestBoundaryX)
				local function checkBoundaryExceeded(recordToCheck)
					local totalIcons = #recordToCheck
					for i = 1, totalIcons do
						local endIcon = recordToCheck[totalIcons+1 - i]
						if IconController.canShowIconOnTopbar(endIcon) then
							local isAnOverflowIcon = string.match(endIcon.name, "_overflowIcon-")
							if isAnOverflowIcon and totalIcons ~= 1 then --!!!
								break
							elseif isAnOverflowIcon and not endIcon.enabled then
								continue
							end
							local additionalMyX = 0
							if not overflowIcon.enabled then
								additionalMyX = START_LEEWAY
							end
							local myBoundaryX = getBoundaryX(endIcon, alignment, additionalMyX)
							local isNowClosest = (alignment == "left" and myBoundaryX < closestBoundaryX) or (alignment == "right" and myBoundaryX > closestBoundaryX)
							if isNowClosest then
								closestBoundaryX = myBoundaryX
								if doesExceed(myBoundaryX) then
									exceededCriticalBoundary = true
								end
							end
						end
					end
				end
				checkBoundaryExceeded(alignmentDetails[oppositeAlignment].records)
				checkBoundaryExceeded(alignmentDetails.mid.records)

				-- This determines which icons to give to the overflow if an overlap is present
				if exceededCriticalBoundary then
					local recordToCheck = alignmentInfo.records
					local totalIcons = #recordToCheck
					for i = 1, totalIcons do
						local endIcon = (alignment == "left" and recordToCheck[totalIcons+1 - i]) or (alignment == "right" and recordToCheck[i])
						if endIcon ~= overflowIcon and IconController.canShowIconOnTopbar(endIcon) then
							local additionalGap = alignmentGap
							local overflowIconSizeX = overflowIcon:get("iconSize", overflowIcon:getIconState()).X.Offset
							if overflowIcon.enabled then
								additionalGap += alignmentGap + overflowIconSizeX
							end
							local myBoundaryXPlusGap = getBoundaryX(endIcon, oppositeAlignment, additionalGap)
							local exceeds = (alignment == "left" and myBoundaryXPlusGap >= closestBoundaryX) or (alignment == "right" and myBoundaryXPlusGap <= closestBoundaryX)
							if exceeds then
								if not overflowIcon.enabled then
									local overflowContainer = overflowIcon.instances.iconContainer
									local yPos = overflowContainer.Position.Y
									local appearXAdditional = (alignment == "left" and -overflowContainer.Size.X.Offset) or 0
									local appearX = getBoundaryX(endIcon, oppositeAlignment, appearXAdditional)
									overflowContainer.Position = UDim2.new(0, appearX, yPos.Scale, yPos.Offset)
									overflowIcon:setEnabled(true)
								end
								if #endIcon.dropdownIcons > 0 then
									endIcon._overflowConvertedToMenu = true
									local wasSelected = endIcon.isSelected
									endIcon:deselect()
									local iconsToConvert = {}
									for _, dIcon in pairs(endIcon.dropdownIcons) do
										table.insert(iconsToConvert, dIcon)
									end
									for _, dIcon in pairs(endIcon.dropdownIcons) do
										dIcon:leave()
									end
									endIcon:setMenu(iconsToConvert)
									if wasSelected and overflowIcon.isSelected then
										endIcon:select()
									end
								end
								endIcon:join(overflowIcon, "dropdown")
								if #endIcon.menuIcons > 0 and endIcon.menuOpen then
									endIcon:deselect()
									endIcon:select()
									overflowIcon:select()
								end
							end
							break
						end
					end
				
				else
					
					-- This checks to see if the lowest/highest (depending on left/right) ordered overlapping icon is no longer overlapping, removes from the dropdown, and repeats if valid
					local winningOrder, winningOverlappedIcon
					local totalOverlappingIcons = #overflowIcon.dropdownIcons
					if not (oppositeOverflowIcon and oppositeOverflowIcon.enabled and #alignmentInfo.records == 1 and #oppositeAlignmentInfo.records ~= 1) then
						for _, overlappedIcon in pairs(overflowIcon.dropdownIcons) do
							local iconOrder = overlappedIcon:get("order")
							if winningOverlappedIcon == nil or (alignment == "left" and iconOrder < winningOrder) or (alignment == "right" and iconOrder > winningOrder) then
								winningOrder = iconOrder
								winningOverlappedIcon = overlappedIcon
							end
						end
					end
					if winningOverlappedIcon then
						local sizeX = getSizeX(winningOverlappedIcon, true)
						local myForesightBoundaryX = getBoundaryX(overflowIcon, oppositeAlignment)
						if totalOverlappingIcons == 1 then
							myForesightBoundaryX = getBoundaryX(overflowIcon, alignment, alignmentGap-START_LEEWAY)
						end
						local availableGap = math.abs(closestBoundaryX - myForesightBoundaryX) - (alignmentGap*2)
						local noLongerExeeds = (sizeX < availableGap)
						if noLongerExeeds then
							if #overflowIcon.dropdownIcons == 1 then
								overflowIcon:setEnabled(false)
							end
							local overflowContainer = overflowIcon.instances.iconContainer
							local yPos = overflowContainer.Position.Y
							overflowContainer.Position = UDim2.new(0, myForesightBoundaryX, yPos.Scale, yPos.Offset)
							winningOverlappedIcon:leave()
							--
							if winningOverlappedIcon._overflowConvertedToMenu then
								winningOverlappedIcon._overflowConvertedToMenu = nil
								local iconsToConvert = {}
								for _, dIcon in pairs(winningOverlappedIcon.menuIcons) do
									table.insert(iconsToConvert, dIcon)
								end
								for _, dIcon in pairs(winningOverlappedIcon.menuIcons) do
									dIcon:leave()
								end
								winningOverlappedIcon:setDropdown(iconsToConvert)
							end
							--
						end
					end

				end
			end
		end
		--------
		if requestedTopbarUpdate then
			requestedTopbarUpdate = false
			IconController.updateTopbar()
		end
		return true
	end)()
end

function IconController.setTopbarEnabled(bool, forceBool)
	if forceBool == nil then
		forceBool = true
	end
	local indicator = TopbarPlusGui.Indicator
	if forceBool and not bool then
		forceTopbarDisabled = true
	elseif forceBool and bool then
		forceTopbarDisabled = false
	end
	if IconController.controllerModeEnabled then
		if bool then
			if TopbarPlusGui.TopbarContainer.Visible or forceTopbarDisabled or menuOpen or not checkTopbarEnabled() then return end
			if forceBool then
				indicator.Visible = checkTopbarEnabled()
			else
				if hapticService:IsVibrationSupported(Enum.UserInputType.Gamepad1) and hapticService:IsMotorSupported(Enum.UserInputType.Gamepad1,Enum.VibrationMotor.Small) then
					hapticService:SetMotor(Enum.UserInputType.Gamepad1,Enum.VibrationMotor.Small,1)
					delay(0.2,function()
						pcall(function()
							hapticService:SetMotor(Enum.UserInputType.Gamepad1,Enum.VibrationMotor.Small,0)
						end)
					end)
				end
				TopbarPlusGui.TopbarContainer.Visible = true
				TopbarPlusGui.TopbarContainer:TweenPosition(
					UDim2.new(0,0,0,5 + STUPID_CONTROLLER_OFFSET),
					Enum.EasingDirection.Out,
					Enum.EasingStyle.Quad,
					0.1,
					true
				)
				
				
				local selectIcon
				local targetOffset = 0
				IconController:_updateSelectionGroup()
				runService.Heartbeat:Wait()
				local indicatorSizeTrip = 50 --indicator.AbsoluteSize.Y * 2
				for otherIcon, _ in pairs(topbarIcons) do
					if IconController.canShowIconOnTopbar(otherIcon) and (selectIcon == nil or otherIcon:get("order") > selectIcon:get("order")) then
						selectIcon = otherIcon
					end
					local container = otherIcon.instances.iconContainer
					local newTargetOffset = -27 + container.AbsoluteSize.Y + indicatorSizeTrip
					if newTargetOffset > targetOffset then
						targetOffset = newTargetOffset
					end
				end
				if guiService:GetEmotesMenuOpen() then
					guiService:SetEmotesMenuOpen(false)
				end
				if guiService:GetInspectMenuEnabled() then
					guiService:CloseInspectMenu()
				end
				local newSelectedObject = IconController._previousSelectedObject or selectIcon.instances.iconButton
				IconController._setControllerSelectedObject(newSelectedObject)
				indicator.Image = "rbxassetid://5278151071"
				indicator:TweenPosition(
					UDim2.new(0.5,0,0,targetOffset + STUPID_CONTROLLER_OFFSET),
					Enum.EasingDirection.Out,
					Enum.EasingStyle.Quad,
					0.1,
					true
				)
			end
		else
			if forceBool then
				indicator.Visible = false
			else
				indicator.Visible = checkTopbarEnabled()
			end
			if not TopbarPlusGui.TopbarContainer.Visible then return end
			guiService.AutoSelectGuiEnabled = true
			IconController:_updateSelectionGroup(true)
			TopbarPlusGui.TopbarContainer:TweenPosition(
				UDim2.new(0,0,0,-TopbarPlusGui.TopbarContainer.Size.Y.Offset + STUPID_CONTROLLER_OFFSET),
				Enum.EasingDirection.Out,
				Enum.EasingStyle.Quad,
				0.1,
				true,
				function()
					TopbarPlusGui.TopbarContainer.Visible = false
				end
			)
			indicator.Image = "rbxassetid://5278151556"
			indicator:TweenPosition(
				UDim2.new(0.5,0,0,5),
				Enum.EasingDirection.Out,
				Enum.EasingStyle.Quad,
				0.1,
				true
			)
		end
	else
		local topbarContainer = TopbarPlusGui.TopbarContainer
		if checkTopbarEnabled() then
			topbarContainer.Visible = bool
		else
			topbarContainer.Visible = false
		end
	end
end

function IconController.setGap(value, alignment)
	local newValue = tonumber(value) or 12
	local newAlignment = tostring(alignment):lower()
	if newAlignment == "left" or newAlignment == "mid" or newAlignment == "right" then
		IconController[newAlignment.."Gap"] = newValue
		return
	end
	IconController.leftGap = newValue
	IconController.midGap = newValue
	IconController.rightGap = newValue
	IconController.updateTopbar()
end

local localPlayer = players.LocalPlayer
local iconsToClearOnSpawn = {}
localPlayer.CharacterAdded:Connect(function()
	for _, icon in pairs(iconsToClearOnSpawn) do
		icon:destroy()
	end
	iconsToClearOnSpawn = {}
end)
function IconController.clearIconOnSpawn(icon)
	coroutine.wrap(function()
		local char = localPlayer.Character or localPlayer.CharacterAdded:Wait()
		table.insert(iconsToClearOnSpawn, icon)
	end)()
end


