Before I post my question I want to get something out of the way: I am not a scripter or anything. I may need some extra explaining
I want to be able to open a GUI when clicking on my topbar. I would prefer not to use the dropdown menus that are built-in because I already have my menu completely configurated.
I have tried some code but I got no results. Nothing happened and there were no output errors.
local Icon = require(game:GetService("ReplicatedStorage").Icon)
local menuicon = Icon.new()
menuicon:setImage(imageId)
menuicon:setLabel("MENU")
menuicon:bindToggleKey(Enum.KeyCode.M)
menuicon:setMid()
local mainFrame = game.StarterGui:WaitForChild("MainMenu")
menuicon:bindToggleItem(mainFrame.mainMenu)
If I need to give any more code or show any screenshots please let me know. Also, this is probably really simple but I am really bad at scripting.
This is because you are trying to bind the GUI in StarterGui to the icon. (StarterGui is used to clone UI elements to PlayerGui on respawn, unless ResetOnSpawn is disabled)
Instead do game:GetService(“Players”).LocalPlayer.PlayerGui:WaitForChild(“MainMenu”), which is the player’s gui container.
I recommend putting game:GetService(“Players”) and LocalPlayer as a variable to keep the code clean.
local ReplicatedStorage = game:GetService("ReplicatedStorage")
local TopBar = require(ReplicatedStorage.Icon)
local mainMenu = script.Parent:FindFirstChild("mainMenu")
local menuicon = TopBar.new()
menuicon:setLabel("MENU")
menuicon:setMid()
menuicon:bindToggleKey(Enum.KeyCode.M)
menuicon.deselected:Connect(function()
print("menuicon has been deselected")
mainMenu.Visible = false
end)
menuicon.selected:Connect(function()
print("menuicon has been selected")
mainMenu.Visible = true
end)