Gui Hiding issues

Hello Developers, Aymoc here.

I’ve recently been making my own game and noticed a problem that I tried to solve that didn’t work.


This is my GUI, and when I click play it is supposed to be Hidden.
The problem is that it doesn’t do what it’s commanded.

Here is the code, that handles what It needs to do.

local Menu = game.StarterGui["Main Menu"]

local Frame = game.StarterGui["Main Menu"].Frame

local PC = game.StarterGui.PartCount

script.Parent.MouseButton1Down:Connect(function()

Frame.Visible = false

Menu.Enabled = false

game.Lighting.Blur:Destroy()

game.PC.Visible = true

end)

Does anyone know the issue here?

2 Likes

Hello, how are you doing?

When the game starts, all of the things inside the StarterGui is cloned inside the player’s PlayerGui folder, so you may change that directory.
Try this:

local Menu = game.Players.LocalPlayer.PlayerGui["Main Menu"]

local Frame = game.Players.LocalPlayer.PlayerGui["Main Menu"].Frame

local PC = game.Players.LocalPlayer.PlayerGui.PartCount

Change MouseButton1Down to MouseButton1Click, because then it will also work to Mobile players.

Note: MouseButton1Down also works for mobile players :wink:.

1 Like

It does?
I’ve tried it sometimes and it didn’t work, even when i went into my own mobile device.
Thanks for letting me know, anyways!

1 Like

Do not use game.StarterGui.["Main Menu"] because then It only will make the GUI in the StarterGui visible and not in the PlayerGui as @TrashMakeRice

Do it like this:

1 Like

Since all the Ui is getting clones to the player, its best to call it within the player. Calling it from StarterGui just does it to everyone in the server basically.

Just a side note, but just identifying the PlayerGui alone without no confirmation could result in an error

Use WaitForChild() to yield the current thread, so that you know that you have the Gui & Frame:

local Player = game.Players.LocalPlayer
local PlayerGui = Player:WaitForChild("PlayerGui")
local Menu = PlayerGui:WaitForChild("Main Menu")
local Frame = Menu.Frame
local PC = game.Players.LocalPlayer.PlayerGui:WaitForChild("PartCount")

script.Parent.MouseButton1Down:Connect(function()
    Frame.Visible = false
    Menu.Enabled = false
    game.Lighting.Blur:Destroy()
    PC.Enabled = true 
end)

My brain has fried whoops

2 Likes

I just noticed this, shouldn’t it be straight up PC.Enabled?

There isn’t anything really defined as a variable called “PC”, so I have no clue it may be defined as some, maybe a GuiObject or something (The rest of the code seems fine however)

Oh yeah, it should. I dont why there is game

PC is already defined here

So why game.PC again?

1 Like

Good catch, edited it :thinking:

1 Like

Looks like it’s like that in the original script as well.

I still have no idea why it’s game.PC.

This was the solution, Thanks.
Thanks to every developer that participated in this and tried to help me out. :grinning_face_with_smiling_eyes: :+1:

1 Like