Settings Button not working as expected... (TopBar Plus)

Trying to make a Settings UI with TopBar Plus.

Whenever I add the PlayerGUI as a variable so I can add my folders as a variable so I can get to where my UI is located, my topbar button disappears and my script throws an error because the folder ‘isn’t a valid member of PlayerGui’.

Please help. :smiling_face_with_tear:


Error in output

Screenshot_1

Script
local Icon = require(game:GetService("ReplicatedStorage").Icon)


local player = game:GetService("Players").LocalPlayer
local playerGui = player.PlayerGui


local MainUIFolder = playerGui.MainUI
local TopBarPlus = MainUIFolder.TopBarPlus

local SettingsUI = TopBarPlus.Settings
local SettingsFrame = TopBarPlus.Settings.Bottom


local icon = Icon.new()

icon:setRight()
icon:setCornerRadius(1, 0)

:setImage(6942070576)
:setLabel("Settings", "hovering")
:setLabel("Close", "selected")
icon:setCaption("Configure settings")


icon:BindToggleItem(SettingsFrame)

icon.deselected:Connect(function()
	SettingsFrame.Visible = false
end)

icon.selected:Connect(function()
	SettingsFrame.Visible = true	
end)

Instead of trying to index it directly, try using :WaitForChild(“MainUI”)

if it returns infinite yield then load into game and check the direct location of the UI.

Add WaitForChild() calls to allow for instances to replicate to the client.

1 Like

Thanks, it works now! :+1: