TopbarPlus commands list not working correctly

Hey devforum! I’m using TopbarPlus v3 to make a commands GUI. The player will select each argument from individual dropdowns. After i finish all arguments of a command, the lists start mixing up (that’s not supposed to happen)

if player.UserId == game.CreatorId or player.UserId == ownerID then 
	local tools = toolsFolder:GetChildren() -- List of tools available
	local players = game.Players:GetPlayers() -- List of players in the server

	-- Initialize main command icon
	local icon = topbarPlus.new()
	icon:setLabel("Commands")
	icon:setCaption("View VIP/Chat Commands")
	icon:modifyTheme({"Dropdown", "MaxIcons", 4})
	icon:modifyChildTheme({"Widget", "MinimumWidth", 30})

	-- Function to clear and reset dropdown
	local function clearAndSetDropdown(newDropdown)
		icon:setDropdown({})  -- Clear the current dropdown
		icon:setDropdown(newDropdown) -- Set the new dropdown items
	end

	-- Function to reset to the main command menu
	local function resetToMainMenu()
		clearAndSetDropdown(setMainCommandDropdown()) -- Clear and reset to main command list
	end

	-- Function to create a dropdown for tools after selecting a player for the `/give` command
	local function createToolDropdown(selectedPlayer)
		local toolDropdown = {}

		for _, tool in pairs(tools) do
			if tool:IsA("Tool") then
				table.insert(toolDropdown, topbarPlus.new()
					:setLabel(tool.Name)
					:bindEvent("selected", function()
						sendNotif("Give Tool", "Gave " .. tool.Name .. " to " .. selectedPlayer.Name)
						-- Implement command functionality here (e.g., server request to give the tool)
						resetToMainMenu() -- Close and reset to the main command menu
					end)
						:oneClick()
				)
			end
		end

		clearAndSetDropdown(toolDropdown)
	end

	-- Function to create a dropdown for backpack items after selecting a player for the `/remove` command
	local function createBackpackDropdown(selectedPlayer)
		local backpackDropdown = {}

		-- Get the player's Backpack contents
		for _, item in pairs(selectedPlayer.Backpack:GetChildren()) do
			if item:IsA("Tool") then
				table.insert(backpackDropdown, topbarPlus.new()
					:setLabel(item.Name)
					:bindEvent("selected", function()
						sendNotif("Remove Tool", "Removed " .. item.Name .. " from " .. selectedPlayer.Name)
						-- Implement command functionality here (e.g., server request to remove the tool)
						resetToMainMenu() -- Close and reset to the main command menu
					end)
						:oneClick()
				)
			end
		end

		clearAndSetDropdown(backpackDropdown)
	end

	-- Function to create a player dropdown based on the selected command
	local function createPlayerDropdown(command)
		local playerDropdown = {}

		for _, player in pairs(players) do
			table.insert(playerDropdown, topbarPlus.new()
				:setLabel(player.Name)
				:bindEvent("selected", function()
					if command == "/give" then
						createToolDropdown(player) -- Show tools for the /give command
					elseif command == "/remove" then
						createBackpackDropdown(player) -- Show backpack items for the /remove command
					elseif command == "/giveBoards" then
						sendNotif("Give Boards", "Gave boards to " .. player.Name)
						-- Implement give boards command functionality
						resetToMainMenu() -- Close and reset to the main command menu
					end
				end)
					:oneClick()
			)
		end

		clearAndSetDropdown(playerDropdown)
	end

	-- Initial command dropdown setup function
	function setMainCommandDropdown()
		return {
			topbarPlus.new()
				:setLabel("/give")
				:bindEvent("selected", function()
					sendNotif("/give Command", "Select a player to give a tool.")
					createPlayerDropdown("/give")
				end)
				:oneClick()
			,

			topbarPlus.new()
				:setLabel("/remove")
				:bindEvent("selected", function()
					sendNotif("/remove Command", "Select a player to remove an item from their backpack.")
					createPlayerDropdown("/remove")
				end)
				:oneClick()
			,

			topbarPlus.new()
				:setLabel("/giveBoards")
				:bindEvent("selected", function()
					sendNotif("/giveBoards Command", "Select a player to give boards.")
					createPlayerDropdown("/giveBoards")
				end)
				:oneClick()
			,

			-- Add more commands as needed
		}
	end

	-- Set the main command dropdown initially
	clearAndSetDropdown(setMainCommandDropdown())
else
	print("Player does not have permission to use VIP commands.")
end

(yes chatgpt helped me)

haven’t gotten anywhere with this so far

Yeah i don’t really know what made that occur.
under clearAndSetDropdown I cleared it again clear and now it works for me,

local function clearAndSetDropdown(newDropdown)
	icon:setDropdown({})  -- Clear the current dropdown
	icon:setDropdown({})
	icon:setDropdown(newDropdown) -- Set the new dropdown items
end
1 Like

i did it three times and it seems to work for now :person_shrugging: ill let you know if it happens again

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.