Script not Enabled Gui

Hello im working with TopbarPlus v2(https://devforum.roblox.com/t/topbarplus-v2-construct-intuitive-topbar-icons/1017485/66) from ForeverHD and its not Enabling a gui!

Code

Script is in StarterPlayerScripts for not duplicating icons!

local Icon = require(game.ReplicatedStorage.Icon)
local PlayerGui = game.Players.LocalPlayer:FindFirstChild("PlayerGui")
local EmotesUI = PlayerGui:FindFirstChild("AnimationsGui").Enabled

local Music = Icon.new()
Music:setLabel("Music")

local Emotes = Icon.new()
Emotes:setLabel("Emotes")

Emotes.selected:Connect(function()
	EmotesUI = not EmotesUI
end)

I tried Visible on the frame but not working…

Have a great day!

local Icon = require(game.ReplicatedStorage.Icon)
local PlayerGui = game.Players.LocalPlayer.PlayerGui
local EmotesUI = PlayerGui:WaitForChild("AnimationsGui")

local Music = Icon.new()
Music:setLabel("Music")

local Emotes = Icon.new()
Emotes:setLabel("Emotes")

Emotes.selected:Connect(function()
	EmotesUI.Enabled = not EmotesUI.Enabled
end)
1 Like

I tested that too and not working…

Are you getting any errors from your output?

Players.baum2409.PlayerScripts.Icons:3: attempt to index nil with 'Enabled'

This means that your emote ui does not exist. Try double checking if the ui does exist.

No clue why you’re not using WaitForChild()

local Icon = require(game.ReplicatedStorage.Icon)
local PlayerGui = game.Players.LocalPlayer:WaitForChild("PlayerGui")
local EmotesUI = PlayerGui:WaitForChild("AnimationsGui")

local Music = Icon.new()
Music:setLabel("Music")

local Emotes = Icon.new()
Emotes:setLabel("Emotes")

Emotes.selected:Connect(function()
	EmotesUI.Enabled = not EmotesUI.Enabled
end)
1 Like

Why is it now working??? befor when im using WaitForChild it was a error!

Probably because your ui has not fully loaded yet.

Sometimes the StarterGui won’t exactly replicate instantly to the Player’s Gui as soon as the Player first joins the game, which is why you call WaitForChild() for the script to yield its line of code until that specific object has been found

If I were to insert this into a Empty Baseplate:

local Part = workspace:WaitForChild("Part")

It’d result as an “infinite yield warning”, cause there’s no Part that I inserted just yet and it’ll keep looping until the Part has been found, or I insert a “timeout” parameter

2 Likes