UPDATED
local Player = game.Players.LocalPlayer local Mouse = Player:GetMouse() local Gui = game.StarterGui local DevMenu = Gui.DevMenu local Main = Gui.DevMenu.MainFrame local Sound = DevMenu.Activater.Sound_1 if Player.Name == "Player1" then game:GetService("UserInputService").InputBegan:Connect(function(input,chat) if not chat then if input.KeyCode == Enum.KeyCode.X then Sound:Play() print("X is down.") DevMenu.Enabled = true else DevMenu.Enabled = false end end end) end
For some reason this wont make the Gui appear when I press x. This is in a LocalScript. When I press X the code fires and I see the the "X is down" in output. Any help is appreciated!
Hi!
The UserInputService is a service class that must be obtained with GetService(). Otherwise this service will not exist in the DataModel.
local Player = game.Players.LocalPlayer local Mouse = Player:GetMouse() local Gui = game.StarterGui local Main = Gui.DevMenu.MainFrame if Player.Name == "AdvancedCode" then game:GetService("UserInputService").InputBegan:Connect(function(input,chat) if not chat then if input.KeyCode == Enum.KeyCode.X then Main.Visible = true else Main.Visible = false end end end) end
Note that your username is "Player1" in test mode, not AdvancedCode. Therefore the if statement won't run unless you're playing in a local server. You can change it to "if Player.Name == "Player1" then" for testing purposes.
You should be using PlayerGui
, not StarterGui
. PlayerGui
is where GUI's get cloned from the StarterGui
to a player
.
local Player = game.Players.LocalPlayer local Mouse = Player:GetMouse() local Gui = Player.PlayerGui local Main = Gui.DevMenu.MainFrame if Player.Name == "AdvancedCode" then game:GetService("UserInputService").InputBegan:Connect(function(input,chat) if not chat then if input.KeyCode == Enum.KeyCode.X then Main.Visible = true else Main.Visible = false end end end) end
Ok, So you need to know how StarterGui works. Apparently StarterGui is where you place your Guis correct? Follow Skeletal's instructions first please so it will work right. So, you need to use PlayerGui instead because your just editing something that's not on your screen. XD
Gui = Player.PlayerGui
That should help!