Gui Open & Close problem

Hello ! I have a little problem with open & close GUI. My gui is in the replicated storage, and i dont know why, but he wont open :

local replicatedStorage = game:GetService("ReplicatedStorage")
local userInputServer = game:GetService("UserInputService")
local guiMenu = game.ReplicatedStorage.Gui.ScreenGui.Frame

userInputServer.InputBegan:Connect(function(input, gameProcessed)
	if input.UserInputType == Enum.UserInputType.Keyboard then
		if input.KeyCode == Enum.KeyCode.M and not gameProcessed then
			guiMenu.Visible = true
		end
		if guiMenu.Visible == true then
			if input.KeyCode == Enum.KeyCode.M and not gameProcessed then
				guiMenu.Visible = false
			end
		end
	end
end)

How can i resolve this?

You can only see GUI’s that are in a your PlayerGui. Everything in Startergui is automatically cloned into their PlayerGui when they join. Just move the screengui into startergui and do the following:

local player = game.Players.LocalPlayer
local userInputServer = game:GetService("UserInputService")
local guiMenu = player.PlayerGui.ScreenGui.Frame

userInputServer.InputBegan:Connect(function(input, gameProcessed)
	if input.UserInputType == Enum.UserInputType.Keyboard then
		if input.KeyCode == Enum.KeyCode.M and not gameProcessed then
			guiMenu.Visible = true
		end
		if guiMenu.Visible == true then
			if input.KeyCode == Enum.KeyCode.M and not gameProcessed then
				guiMenu.Visible = false
			end
		end
	end
end)
3 Likes

You forgot the Gui before “.ScreenGui” but … it wont works : they say “Gui is not a valid member of PlayerGui “Players.Moldard.PlayerGui” - Client - Menu:3”

Hello, how are you doing?

Try changing this line into:

local guiMenu = player.PlayerGui:WaitForChild("ScreenGui"):WaitForChild("Frame")

1 Like

hello :slight_smile:
It say that : image

The problem is that it’s gonna keep repeating “wait” and that code until it finds the specific child you’ve set.

It’s not gonna run anything else UNTIL it finds it
If it gives you infinite yield, it means it’s taking a long while to find it and there’s a chance it’s not even in there.

Are you sure you named the parts right? Are you sure that you didn’t misstype the directory’s name?
Plus, i’m suspecting that is from another script, not the one we’re talking about right now. Since the warning is at line 1, but with this code right now it should be “line 3”

Oh yes sorry im do a mistake haha but the problem is the same for the script we talk about. So what did i do ?

Below this line, put:
print(guiMenu.Parent.Name)
Then run the code and see if it prints or not.
Also please send a photo the entire console.

It print “screenGui”

That means it found the part successfully.
Try pressing M now.

If it still didn’t work, check if the ScreenGui’s visible is true
If it’s false, set it to true and make the Frame’s visible false.

Then try it again.

I’m suspecting i found you’re problem
Let me make another reply.

Just put a ScreenGui under StarterGui, put a local script in the screenGui and write the following in the local script:

local userInputService = game:GetService("UserInputService")
local gui = script.Parent
userInputService.InputBegan:Connect(function(input,gameProcessed)
    if input.KeyCode == Enum.KeyCode.M and not gameProcessed then
        gui.Enabled = not gui.Enabled
    end
end)

Ok, i think too but i still have a problm :
My screenGui is enable, and my frame’s visible set to false.
but it still wont work

but if i set my frame visible to true, it work only one time : i click on M, the gui close, and when i click back M, nothing work

local player = game.Players.LocalPlayer
local userInputServer = game:GetService("UserInputService")
local guiMenu = player.PlayerGui:WaitForChild("ScreenGui"):WaitForChild("Frame")
local Open = false

userInputServer.InputBegan:Connect(function(input, gameProcessed)
	if input.UserInputType == Enum.UserInputType.Keyboard then
		if input.KeyCode == Enum.KeyCode.M and not gameProcessed then
			if Open then
				guiMenu.Visible = false
				Open = false
			else
				Open = true
				guiMenu.Visible = true   
			end
		end
	end	
end)

Try this out.

1 Like

Why not just

if guiMenu.Visible == true then
    guiMenu.Visible = false
else
    guiMenu.Visible = true
end
2 Likes

I was trying to make one code that adapted to his one, but yeah, that’s also an alternative.

1 Like

It work thank you man !!! Amazing :stuck_out_tongue:

No problem, glad i could help you figure out you’re problem!

1 Like

you can go even simpler

guiMenu.Visible = not guiMenu.Visible
2 Likes

Oh wow, that’s even more simple than what i was thinking of.