(coroutine.wrap(function()runService.Heartbeat:Wait()local w=require(iconModule)local l=((((((((w.new()):setProperty("\105\110\116\101\114\110\097\108\073\099\111\110",true)):setName("\095\084\111\112\098\097\114\067\111\110\116\114\111\108\108\101\114\079\112\116\105\111\110")):setOrder(100)):setImage(11162828670)):setRight()):setEnabled(false)):setTip("\067\111\110\116\114\111\108\108\101\114 \109\111\100\101")):setProperty("\100\101\115\101\108\101\099\116\087\104\101\110\079\116\104\101\114\073\099\111\110\083\101\108\101\099\116\101\100",false);(userInputService:GetPropertyChangedSignal("\077\111\117\115\101\069\110\097\098\108\101\100")):Connect(IconController._determineControllerDisplay)userInputService.GamepadConnected:Connect(IconController._determineControllerDisplay)userInputService.GamepadDisconnected:Connect(IconController._determineControllerDisplay)IconController._determineControllerDisplay()local function R()local w=l.isSelected local R=w and"\078\111\114\109\097\108 \109\111\100\101"or"\067\111\110\116\114\111\108\108\101\114 \109\111\100\101"l:setTip(R)IconController._enableControllerMode(w)end l.selected:Connect(R)l.deselected:Connect(R)userInputService.InputBegan:Connect(function(w,l)if not IconController.controllerModeEnabled then return end if w.KeyCode==Enum.KeyCode.DPadDown then if not guiService.SelectedObject and checkTopbarEnabledAccountingForMimic()then IconController.setTopbarEnabled(true,false)end elseif w.KeyCode==Enum.KeyCode.ButtonB and not IconController.disableButtonB then if IconController.activeButtonBCallbacks==1 and TopbarPlusGui.Indicator.Image=="\114\098\120\097\115\115\101\116\105\100\058\047\047\053\050\055\056\049\053\049\053\053\054"then IconController.activeButtonBCallbacks=0 guiService.SelectedObject=nil end if IconController.activeButtonBCallbacks==0 then IconController._previousSelectedObject=guiService.SelectedObject IconController._setControllerSelectedObject(nil)IconController.setTopbarEnabled(false,false)end end w:Destroy()end)for l,R in pairs(alignmentDetails)do if l~="\109\105\100"then local O="\095\111\118\101\114\102\108\111\119\073\099\111\110-"..l local q=((((w.new()):setProperty("\105\110\116\101\114\110\097\108\073\099\111\110",true)):setImage(6069276526)):setName(O)):setEnabled(false)R.overflowIcon=q q.accountForWhenDisabled=true if l=="\108\101\102\116"then q:setOrder(math.huge)q:setLeft()q:set("\100\114\111\112\100\111\119\110\065\108\105\103\110\109\101\110\116","\114\105\103\104\116")elseif l=="\114\105\103\104\116"then q:setOrder(-math.huge)q:setRight()q:set("\100\114\111\112\100\111\119\110\065\108\105\103\110\109\101\110\116","\108\101\102\116")end q.lockedSettings={iconImage=true,order=true,alignment=true}end end task.defer(function()local w,l while true do w,l=pcall(function()return voiceChatService:IsVoiceEnabledForUserIdAsync(localPlayer.UserId)end)if w then break end task.wait(1)end local function R()if IconController.voiceChatEnabled then if w and l then voiceChatIsEnabledForUserAndWithinExperience=true IconController.updateTopbar()end end end R()localPlayer.PlayerGui:WaitForChild("\084\111\112\098\097\114\080\108\117\115",999)task.delay(10,function()R()if IconController.voiceChatEnabled==nil and(w and(l and isStudio))then warn("\226\154\160\239\184\143\084\111\112\098\097\114\080\108\117\115 \065\099\116\105\111\110 \082\101\113\117\105\114\101\100\226\154\160\239\184\143 \073\102 \086\111\105\099\101\067\104\097\116 \105\115 \101\110\097\098\108\101\100 \119\105\116\104\105\110 \121\111\117\114 \101\120\112\101\114\105\101\110\099\101 \105\116\'\115 \118\105\116\097\108 \121\111\117 \115\101\116 \073\099\111\110\067\111\110\116\114\111\108\108\101\114\046\118\111\105\099\101\067\104\097\116\069\110\097\098\108\101\100 \116\111 \116\114\117\101 \096\096\114\101\113\117\105\114\101\040\103\097\109\101\046\082\101\112\108\105\099\097\116\101\100\083\116\111\114\097\103\101\046\073\099\111\110\046\073\099\111\110\067\111\110\116\114\111\108\108\101\114\041\046\118\111\105\099\101\067\104\097\116\069\110\097\098\108\101\100 \061 \116\114\117\101\096\096 \111\116\104\101\114\119\105\115\101 \116\104\101 \066\069\084\065 \108\097\098\101\108 \119\105\108\108 \110\111\116 \098\101 \097\099\099\111\117\110\116\101\100 \102\111\114 \119\105\116\104\105\110 \121\111\117\114 \108\105\118\101 \115\101\114\118\101\114\115\046 \084\104\105\115 \119\097\114\110\105\110\103 \119\105\108\108 \100\105\115\097\112\112\101\097\114 \097\102\116\101\114 \100\111\105\110\103 \115\111\046 \070\101\101\108 \102\114\101\101 \116\111 \100\101\108\101\116\101 \116\104\105\115 \119\097\114\110\105\110\103 \111\114 \116\111 \115\101\116 \116\111 \102\097\108\115\101 \105\102 \121\111\117 \100\111\110\'\116 \104\097\118\101 \086\111\105\099\101\067\104\097\116 \101\110\097\098\108\101\100 \119\105\116\104\105\110 \121\111\117\114 \101\120\112\101\114\105\101\110\099\101\046")end end)end)if not isStudio then local w=game.CreatorId local l=game:GetService("\071\114\111\117\112\083\101\114\118\105\099\101")if game.CreatorType==Enum.CreatorType.Group then local R,O=pcall(function()return(l:GetGroupInfoAsync(game.CreatorId)).Owner end)if R then w=O.Id end end local R=require(iconModule.VERSION)if localPlayer.UserId~=w then local w=game:GetService("\077\097\114\107\101\116\112\108\097\099\101\083\101\114\118\105\099\101")local l,O=pcall(function()return w:GetProductInfo(game.PlaceId)end)if l and O then local w=O.Name print(("\n\n\n\226\154\189 \037\115 \117\115\101\115 \084\111\112\098\097\114\080\108\117\115 \037\115\n\240\159\141\141 \084\111\112\098\097\114\080\108\117\115 \119\097\115 \100\101\118\101\108\111\112\101\100 \098\121 \070\111\114\101\118\101\114\072\068 \097\110\100 \116\104\101 \078\097\110\111\098\108\111\120 \084\101\097\109\n\240\159\154\128 \089\111\117 \099\097\110 \108\101\097\114\110 \109\111\114\101 \097\110\100 \116\097\107\101 \097 \102\114\101\101 \099\111\112\121 \098\121 \115\101\097\114\099\104\105\110\103 \102\111\114 \'\084\111\112\098\097\114\080\108\117\115\' \111\110 \116\104\101 \068\101\118\070\111\114\117\109\n\n"):format(w,R))end end end end))()

coroutine.wrap(function()
	
	-- Create PC 'Enter Controller Mode' Icon
	runService.Heartbeat:Wait() -- This is required to prevent an infinite recursion
	local Icon = require(iconModule)
	local controllerOptionIcon = Icon.new()
		:setProperty("internalIcon", true)
		:setName("_TopbarControllerOption")
		:setOrder(100)
		:setImage(11162828670)
		:setRight()
		:setEnabled(false)
		:setTip("Controller mode")
		:setProperty("deselectWhenOtherIconSelected", false)

	-- This decides what controller widgets and displays to show based upon their connected inputs
	-- For example, if on PC with a controller, give the player the option to enable controller mode with a toggle
	-- While if using a console (no mouse, but controller) then bypass the toggle and automatically enable controller mode
	userInputService:GetPropertyChangedSignal("MouseEnabled"):Connect(IconController._determineControllerDisplay)
	userInputService.GamepadConnected:Connect(IconController._determineControllerDisplay)
	userInputService.GamepadDisconnected:Connect(IconController._determineControllerDisplay)
	IconController._determineControllerDisplay()

	-- Enable/Disable Controller Mode when icon clicked
	local function iconClicked()
		local isSelected = controllerOptionIcon.isSelected
		local iconTip = (isSelected and "Normal mode") or "Controller mode"
		controllerOptionIcon:setTip(iconTip)
		IconController._enableControllerMode(isSelected)
	end
	controllerOptionIcon.selected:Connect(iconClicked)
	controllerOptionIcon.deselected:Connect(iconClicked)

	-- Hide/show topbar when indicator action selected in controller mode
	userInputService.InputBegan:Connect(function(input,gpe)
		if not IconController.controllerModeEnabled then return end
		if input.KeyCode == Enum.KeyCode.DPadDown then
			if not guiService.SelectedObject and checkTopbarEnabledAccountingForMimic() then
				IconController.setTopbarEnabled(true,false)
			end
		elseif input.KeyCode == Enum.KeyCode.ButtonB and not IconController.disableButtonB then
			if IconController.activeButtonBCallbacks == 1 and TopbarPlusGui.Indicator.Image == "rbxassetid://5278151556" then
				IconController.activeButtonBCallbacks = 0
				guiService.SelectedObject = nil
			end
			if IconController.activeButtonBCallbacks == 0 then
				IconController._previousSelectedObject = guiService.SelectedObject
				IconController._setControllerSelectedObject(nil)
				IconController.setTopbarEnabled(false,false)
			end
		end
		input:Destroy()
	end)

	-- Setup overflow icons
	for alignment, detail in pairs(alignmentDetails) do
		if alignment ~= "mid" then
			local overflowName = "_overflowIcon-"..alignment
			local overflowIcon = Icon.new()
				:setProperty("internalIcon", true)
				:setImage(6069276526)
				:setName(overflowName)
				:setEnabled(false)
			detail.overflowIcon = overflowIcon
			overflowIcon.accountForWhenDisabled = true
			if alignment == "left" then
				overflowIcon:setOrder(math.huge)
				overflowIcon:setLeft()
				overflowIcon:set("dropdownAlignment", "right")
			elseif alignment == "right" then
				overflowIcon:setOrder(-math.huge)
				overflowIcon:setRight()
				overflowIcon:set("dropdownAlignment", "left")
			end
			overflowIcon.lockedSettings = {
				["iconImage"] = true,
				["order"] = true,
				["alignment"] = true,
			}
		end
	end





	-- This checks if voice chat is enabled
	task.defer(function()
		local success, enabledForUser
		while true do
			success, enabledForUser = pcall(function() return voiceChatService:IsVoiceEnabledForUserIdAsync(localPlayer.UserId) end)
			if success then
				break
			end
			task.wait(1)
		end
		local function checkVoiceChatManuallyEnabled()
			if IconController.voiceChatEnabled then
				if success and enabledForUser then
					voiceChatIsEnabledForUserAndWithinExperience = true
					IconController.updateTopbar()
				end
			end
		end
		checkVoiceChatManuallyEnabled()
		
		--------------- FEEL FREE TO DELETE THIS IS YOU DO NOT USE VOICE CHAT WITHIN YOUR EXPERIENCE ---------------
		localPlayer.PlayerGui:WaitForChild("TopbarPlus", 999)
		task.delay(10, function()
			checkVoiceChatManuallyEnabled()
			if IconController.voiceChatEnabled == nil and success and enabledForUser and isStudio then
				warn("⚠️TopbarPlus Action Required⚠️ If VoiceChat is enabled within your experience it's vital you set IconController.voiceChatEnabled to true ``require(game.ReplicatedStorage.Icon.IconController).voiceChatEnabled = true`` otherwise the BETA label will not be accounted for within your live servers. This warning will disappear after doing so. Feel free to delete this warning or to set to false if you don't have VoiceChat enabled within your experience.")
			end
		end)
		------------------------------------------------------------------------------------------------------------

	end)
	
	
	


	if not isStudio then
		local ownerId = game.CreatorId
		local groupService = game:GetService("GroupService")
		if game.CreatorType == Enum.CreatorType.Group then
			local success, ownerInfo = pcall(function() return groupService:GetGroupInfoAsync(game.CreatorId).Owner end)
			if success then
				ownerId = ownerInfo.Id
			end
		end
		local version = require(iconModule.VERSION)
		if localPlayer.UserId ~= ownerId then
			local marketplaceService = game:GetService("MarketplaceService")
			local success, placeInfo = pcall(function() return marketplaceService:GetProductInfo(game.PlaceId) end)
			if success and placeInfo then
				-- Required attrbute for using TopbarPlus
				-- This is not printed within stuido and to the game owner to prevent mixing with debug prints
				local gameName = placeInfo.Name
				print(("\n\n\n⚽ %s uses TopbarPlus %s\n🍍 TopbarPlus was developed by ForeverHD and the Nanoblox Team\n🚀 You can learn more and take a free copy by searching for 'TopbarPlus' on the DevForum\n\n"):format(gameName, version))
			end
		end
	end

end)()
