So upon editing the Core Gui’s for my game (removing the leaderboard, chat etc.). So when the player is in the menu all Core Gui’s are meant to be invisible. But upon testing my game I got this error:
Main is not a valid member of PlayerGui "Players.pinchpotmonster.PlayerGui"
Here is the script:
local StarterGui = game:GetService("StarterGui")
local player = game.Players.LocalPlayer
if player.PlayerGui.Main.Menu.Visible == true then
StarterGui:SetCoreGuiEnabled(Enum.CoreGuiType.All, true)
else
StarterGui:SetCoreGuiEnabled(Enum.CoreGuiType.All, true)
StarterGui:SetCoreGuiEnabled(Enum.CoreGuiType.PlayerList, true)
end
local StarterGui = game:GetService("StarterGui")
local player = game.Players.LocalPlayer
local plrgui = player:WaitForChild("PlayerGui")
local main = plrgui:WaitForChild("Main")
if main.Menu.Visible == true then
StarterGui:SetCoreGuiEnabled(Enum.CoreGuiType.All, true)
else
StarterGui:SetCoreGuiEnabled(Enum.CoreGuiType.All, true)
StarterGui:SetCoreGuiEnabled(Enum.CoreGuiType.PlayerList, true)
end
If you get that error on Menu, just WaitForChild on Menu as well
That seems to only put a stop to the errors occurring within the Output. Though the problem still continues, The leaderboard, chat, player inventory remain visible whilst the menu is still open.
Also I am sorry I made a small typo in the code that doesn’t effect it really but the error was:
The error is because the script fires so quickly the GUI doesn’t have time to be replicated properly just to prove that it works just add a wait(n) at the start of the script, obviously this is not the solution but it will give you an idea what do you have to do, the script gets replicated and starts working much faster than the GUI itself
local StarterGui = game:GetService("StarterGui")
local player = game.Players.LocalPlayer
local PlayerGui = player:WaitForChild("PlayerGui")
local main = PlayerGui:WaitForChild("Main")
local menu = main:WaitForChild("Menu")
wait(1)
if menu.Visible == true then
game.StarterGui:SetCoreGuiEnabled(Enum.CoreGuiType.All,true)
else
game.StarterGui:SetCoreGuiEnabled(Enum.CoreGuiType.All,false)
game.StarterGui:SetCoreGuiEnabled(Enum.CoreGuiType.PlayerList,true)
end
local StarterGui = game:GetService("StarterGui")
local player = game.Players.LocalPlayer
local plrgui = player:WaitForChild("PlayerGui")
local main = plrgui:WaitForChild("Main")
wait(5)
if main.Menu.Visible == true then
StarterGui:SetCoreGuiEnabled(Enum.CoreGuiType.All, true)
else
StarterGui:SetCoreGuiEnabled(Enum.CoreGuiType.All, false)
StarterGui:SetCoreGuiEnabled(Enum.CoreGuiType.PlayerList, true)
end
local StarterGui = game:GetService("StarterGui")
local Main = game.Players.LocalPlayer:WaitForChild("PlayerGui"):WaitForChild("Main")
local Menu = Main:WaitForChild("Menu")
if Main and Menu.Visible then
StarterGui:SetCoreGuiEnabled(Enum.CoreGuiType.All, true)
else
StarterGui:SetCoreGuiEnabled(Enum.CoreGuiType.All, true)
StarterGui:SetCoreGuiEnabled(Enum.CoreGuiType.PlayerList, true)
end
Menu.Changed:Connect(function()
if Main and Menu.Visible then
StarterGui:SetCoreGuiEnabled(Enum.CoreGuiType.All, true)
else
StarterGui:SetCoreGuiEnabled(Enum.CoreGuiType.All, true)
StarterGui:SetCoreGuiEnabled(Enum.CoreGuiType.PlayerList, true)
end
end)
If we connect this to the Changed event, then the CoreGuis will update as the state of Menu is changed.
that shouldn’t do anything you have the wait before the variables
I usually wait a frame before or just move the script in PlayerGUI as it will be replicated once with the GUI
local RunService = game:GetService("RunService")
local player = game.Players.LocalPlayer
RunService.Heartbeat:Wait()
local StarterGui = game:GetService("StarterGui")
local plrgui = player:WaitForChild("PlayerGui")
local main = plrgui:WaitForChild("Main")
if main.Menu.Visible == true then
StarterGui:SetCoreGuiEnabled(Enum.CoreGuiType.All, true)
else
StarterGui:SetCoreGuiEnabled(Enum.CoreGuiType.All, false)
StarterGui:SetCoreGuiEnabled(Enum.CoreGuiType.PlayerList, true)
end