local g=false function IconController.updateTopbar()local function L(g,L)local m=g:get("\105\099\111\110\083\105\122\101",g:getIconState())or UDim2.new(0,32,0,32)local q=m.X.Offset local j=IconController[L.."\071\097\112"]local k=q+j local r=k local N=0 if g._parentIcon==nil then local L,m,q=IconController.getMenuOffset(g)N+=L r+=m+q end return r,N end if topbarUpdating then g=true return false end task.defer(function()topbarUpdating=true runService.Heartbeat:Wait()topbarUpdating=false for g,L in pairs(alignmentDetails)do L.records={}end for g,L in pairs(topbarIcons)do if IconController.canShowIconOnTopbar(g)then local L=g:get("\097\108\105\103\110\109\101\110\116")table.insert(alignmentDetails[L].records,g)end end local m=workspace.CurrentCamera.ViewportSize for g,q in pairs(alignmentDetails)do local j=q.records if#j>1 then if q.reverseSort then table.sort(j,function(g,L)return g:get("\111\114\100\101\114")>L:get("\111\114\100\101\114")end)else table.sort(j,function(g,L)return g:get("\111\114\100\101\114")<L:get("\111\114\100\101\114")end)end end local k=0 for m,q in pairs(j)do local j=L(q,g)k=k+j end local r=q.getStartOffset(k,g)local N=r local e=TopbarPlusGui.TopbarContainer.AbsoluteSize.X for m,j in pairs(j)do local k,r=L(j,g)local A=(q.startScale*e+N)+r N=N+k end for j,k in pairs(j)do local N=k.instances.iconContainer local e,A=L(k,g)local t=k.topPadding local f=UDim2.new(q.startScale,r+A,t.Scale,t.Offset)local H=string.match(k.name,"\095\111\118\101\114\102\108\111\119\073\099\111\110-")local y=k:get("\114\101\112\111\115\105\116\105\111\110\073\110\102\111")if y then(tweenService:Create(N,y,{Position=f})):Play()else N.Position=f end r=r+e k.targetPosition=UDim2.new(0,f.X.Scale*m.X+f.X.Offset,0,f.Y.Scale*m.Y+f.Y.Offset)end end local q=10 local function j(g,L,m)local q=m or 0 local j=g:get("\105\099\111\110\083\105\122\101",g:getIconState())local k=j.X.Offset local r,N=IconController.getMenuOffset(g)local e=L=="\108\101\102\116"and-q-r or L=="\114\105\103\104\116"and(k+q)+N local A=g.targetPosition.X.Offset+e return A end local function k(g,L)local m,q=g:get("\105\099\111\110\083\105\122\101",g:getIconState(),"\098\101\102\111\114\101\068\114\111\112\100\111\119\110")local j=g:get("\105\099\111\110\083\105\122\101","\104\111\118\101\114\105\110\103")if g.wasHoveringBeforeOverflow and(q and(j and j.X.Offset>q.X.Offset))then q=j end local k=L and q or m local r,N=IconController.getMenuOffset(g)local e=(k.X.Offset+r)+N return e end for g,L in pairs(alignmentDetails)do local r=L.overflowIcon if r then local N=IconController[g.."\071\097\112"]local e=g=="\108\101\102\116"and"\114\105\103\104\116"or"\108\101\102\116"local A=alignmentDetails[e]local t=IconController.getIcon("\095\111\118\101\114\102\108\111\119\073\099\111\110-"..e)local f=j(r,g)if r.enabled then f=j(r,e,N)end local function H(L)local m=g=="\108\101\102\116"and L<f or g=="\114\105\103\104\116"and L>f return m end local y=A.getOffset()if not r.enabled then y+=q end local h=g=="\108\101\102\116"and m.X-y or g=="\114\105\103\104\116"and y local a=h local p=H(a)local function z(L)local m=#L for k=1,m,1 do local N=L[(m+1)-k]if IconController.canShowIconOnTopbar(N)then local L=string.match(N.name,"\095\111\118\101\114\102\108\111\119\073\099\111\110-")if L and m~=1 then break elseif L and not N.enabled then continue end local k=0 if not r.enabled then k=q end local e=j(N,g,k)local A=g=="\108\101\102\116"and e<a or g=="\114\105\103\104\116"and e>a if A then a=e if H(e)then p=true end end end end end z(alignmentDetails[e].records)z(alignmentDetails.mid.records)if p then local m=L.records local q=#m for L=1,q,1 do local k=g=="\108\101\102\116"and m[(q+1)-L]or g=="\114\105\103\104\116"and m[L]if k~=r and IconController.canShowIconOnTopbar(k)then local L=N local m=(r:get("\105\099\111\110\083\105\122\101",r:getIconState())).X.Offset if r.enabled then L+=N+m end local q=j(k,e,L)local A=g=="\108\101\102\116"and q>=a or g=="\114\105\103\104\116"and q<=a if A then if not r.enabled then local L=r.instances.iconContainer local m=L.Position.Y local q=g=="\108\101\102\116"and-L.Size.X.Offset or 0 local N=j(k,e,q)L.Position=UDim2.new(0,N,m.Scale,m.Offset)r:setEnabled(true)end if#k.dropdownIcons>0 then k._overflowConvertedToMenu=true local g=k.isSelected k:deselect()local L={}for g,m in pairs(k.dropdownIcons)do table.insert(L,m)end for g,L in pairs(k.dropdownIcons)do L:leave()end k:setMenu(L)if g and r.isSelected then k:select()end end if k.hovering then k.wasHoveringBeforeOverflow=true end k:join(r,"\100\114\111\112\100\111\119\110")if#k.menuIcons>0 and k.menuOpen then k:deselect()k:select()r:select()end end break end end else local m,f local H=#r.dropdownIcons if not(t and(t.enabled and(#L.records==1 and#A.records~=1)))then for L,q in pairs(r.dropdownIcons)do local j=q:get("\111\114\100\101\114")if f==nil or g=="\108\101\102\116"and j<m or g=="\114\105\103\104\116"and j>m then m=j f=q end end end if f then local L=k(f,true)local m=j(r,e)if H==1 then m=j(r,g,N-q)end local A=math.abs(a-m)-N*2 local t=L<A if t then if#r.dropdownIcons==1 then r:setEnabled(false)end local g=r.instances.iconContainer local L=g.Position.Y g.Position=UDim2.new(0,m,L.Scale,L.Offset)f:leave()f.wasHoveringBeforeOverflow=nil if f._overflowConvertedToMenu then f._overflowConvertedToMenu=nil local g={}for L,m in pairs(f.menuIcons)do table.insert(g,m)end for g,L in pairs(f.menuIcons)do L:leave()end f:setDropdown(g)end end end end end end if g then g=false IconController.updateTopbar()end return true end)end function IconController.setTopbarEnabled(g,L)if L==nil then L=true end local m=TopbarPlusGui.Indicator if L and not g then forceTopbarDisabled=true elseif L and g then forceTopbarDisabled=false end local q=checkTopbarEnabledAccountingForMimic()if IconController.controllerModeEnabled then if g then if TopbarPlusGui.TopbarContainer.Visible or forceTopbarDisabled or menuOpen or not q then return end if L then m.Visible=q else m.Active=false if controllerMenuOverride and controllerMenuOverride.Connected then controllerMenuOverride:Disconnect()end 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 g local L=0 IconController:_updateSelectionGroup()runService.Heartbeat:Wait()local q=50 for m,j in pairs(topbarIcons)do if IconController.canShowIconOnTopbar(m)and((g==nil or m:get("\111\114\100\101\114")<g:get("\111\114\100\101\114"))and m.enabled)then g=m end local k=m.instances.iconContainer local r=(-27+k.AbsoluteSize.Y)+q if r>L then L=r end end if guiService:GetEmotesMenuOpen()then guiService:SetEmotesMenuOpen(false)end if guiService:GetInspectMenuEnabled()then guiService:CloseInspectMenu()end local j=IconController._previousSelectedObject or g.instances.iconButton IconController._setControllerSelectedObject(j)m.Image="\114\098\120\097\115\115\101\116\105\100\058\047\047\053\050\055\056\049\053\049\048\055\049"m:TweenPosition(UDim2.new(.5,0,0,L+STUPID_CONTROLLER_OFFSET),Enum.EasingDirection.Out,Enum.EasingStyle.Quad,.1,true)end else if L then m.Visible=false elseif q then m.Visible=true m.Active=true controllerMenuOverride=m.InputBegan:Connect(function(g)if g.UserInputType==Enum.UserInputType.MouseButton1 then IconController.setTopbarEnabled(true,false)end end)else m.Visible=false 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)m.Image="\114\098\120\097\115\115\101\116\105\100\058\047\047\053\050\055\056\049\053\049\053\053\054"m:TweenPosition(UDim2.new(.5,0,0,5),Enum.EasingDirection.Out,Enum.EasingStyle.Quad,.1,true)end else local L=TopbarPlusGui.TopbarContainer if q then L.Visible=g else L.Visible=false end end end function IconController.setGap(g,L)local m=tonumber(g)or 12 local q=(tostring(L)):lower()if q=="\108\101\102\116"or q=="\109\105\100"or q=="\114\105\103\104\116"then IconController[q.."\071\097\112"]=m IconController.updateTopbar()return end IconController.leftGap=m IconController.midGap=m IconController.rightGap=m IconController.updateTopbar()end function IconController.setLeftOffset(g)IconController.leftOffset=tonumber(g)or 0 IconController.updateTopbar()end function IconController.setRightOffset(g)IconController.rightOffset=tonumber(g)or 0 IconController.updateTopbar()end local L=players.LocalPlayer local m={}L.CharacterAdded:Connect(function()for g,L in pairs(m)do L:destroy()end m={}end)function IconController.clearIconOnSpawn(g)(coroutine.wrap(function()local q=L.Character or L.CharacterAdded:Wait()table.insert(m,g)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
	task.defer(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 hoveringSize = iconToCheck:get("iconSize", "hovering")
			if iconToCheck.wasHoveringBeforeOverflow and previousSize and hoveringSize and hoveringSize.X.Offset > previousSize.X.Offset then
				-- This prevents hovering icons flicking back and forth, demonstrated at thread/1017485/191.
				previousSize = hoveringSize
			end
			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
								if endIcon.hovering then
									endIcon.wasHoveringBeforeOverflow = true
								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()
							winningOverlappedIcon.wasHoveringBeforeOverflow = nil
							--
							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
	local topbarEnabledAccountingForMimic = checkTopbarEnabledAccountingForMimic()
	if IconController.controllerModeEnabled then
		if bool then
			if TopbarPlusGui.TopbarContainer.Visible or forceTopbarDisabled or menuOpen or not topbarEnabledAccountingForMimic then return end
			if forceBool then
				indicator.Visible = topbarEnabledAccountingForMimic
			else
				indicator.Active = false
				if controllerMenuOverride and controllerMenuOverride.Connected then
					controllerMenuOverride:Disconnect()
				end
				
				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")) and otherIcon.enabled 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
			elseif topbarEnabledAccountingForMimic then
				indicator.Visible = true
				indicator.Active = true
				controllerMenuOverride = indicator.InputBegan:Connect(function(input)
					if input.UserInputType == Enum.UserInputType.MouseButton1 then
						IconController.setTopbarEnabled(true,false)
					end
				end)
			else
				indicator.Visible = false
			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 topbarEnabledAccountingForMimic 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
		IconController.updateTopbar()
		return
	end
	IconController.leftGap = newValue
	IconController.midGap = newValue
	IconController.rightGap = newValue
	IconController.updateTopbar()
end

function IconController.setLeftOffset(value)
	IconController.leftOffset = tonumber(value) or 0
	IconController.updateTopbar()
end

function IconController.setRightOffset(value)
	IconController.rightOffset = tonumber(value) or 0
	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


