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)
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)
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”
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”
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)
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)