UPDATED
01 | local Player = game.Players.LocalPlayer |
02 | local Mouse = Player:GetMouse() |
03 | local Gui = game.StarterGui |
04 | local DevMenu = Gui.DevMenu |
05 | local Main = Gui.DevMenu.MainFrame |
06 | local Sound = DevMenu.Activater.Sound_ 1 |
07 |
08 | if Player.Name = = "Player1" then |
09 | game:GetService( "UserInputService" ).InputBegan:Connect( function (input,chat) |
10 | if not chat then |
11 | if input.KeyCode = = Enum.KeyCode.X then |
12 | Sound:Play() |
13 | print ( "X is down." ) |
14 | DevMenu.Enabled = true |
15 | else |
16 | DevMenu.Enabled = false |
17 | end |
18 | end |
19 | end ) |
20 | 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.
01 | local Player = game.Players.LocalPlayer |
02 | local Mouse = Player:GetMouse() |
03 | local Gui = game.StarterGui |
04 | local Main = Gui.DevMenu.MainFrame |
05 |
06 | if Player.Name = = "AdvancedCode" then |
07 | game:GetService( "UserInputService" ).InputBegan:Connect( function (input,chat) |
08 | if not chat then |
09 | if input.KeyCode = = Enum.KeyCode.X then |
10 | Main.Visible = true |
11 | else |
12 | Main.Visible = false |
13 | end |
14 | end |
15 | end ) |
16 | 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
.
01 | local Player = game.Players.LocalPlayer |
02 | local Mouse = Player:GetMouse() |
03 | local Gui = Player.PlayerGui |
04 | local Main = Gui.DevMenu.MainFrame |
05 |
06 | if Player.Name = = "AdvancedCode" then |
07 | game:GetService( "UserInputService" ).InputBegan:Connect( function (input,chat) |
08 | if not chat then |
09 | if input.KeyCode = = Enum.KeyCode.X then |
10 | Main.Visible = true |
11 | else |
12 | Main.Visible = false |
13 | end |
14 | end |
15 | end ) |
16 | 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
1 | Gui = Player.PlayerGui |
That should help!