Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

When I push the key down, the Gui wont appear?

Asked by 7 years ago
Edited 7 years ago

UPDATED

01local Player = game.Players.LocalPlayer
02local Mouse = Player:GetMouse()
03local Gui = game.StarterGui
04local DevMenu = Gui.DevMenu
05local Main = Gui.DevMenu.MainFrame
06local Sound = DevMenu.Activater.Sound_1
07 
08if Player.Name == "Player1" then
09game:GetService("UserInputService").InputBegan:Connect(function(input,chat)
10if 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)
20end

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!

0
I don't see 'Gui' defined anywhere - have you defined it in your script? It is most likely the reason it does not work. TheDeadlyPanther 2460 — 7y
0
Not the problem. AdvancedCode 136 — 7y
0
You seem to be missing an end at the bottom of your code. You should fix your formatting so it can be easy to tell when you're missing something. TheDeadlyPanther 2460 — 7y
0
Yeah, that didn't work either. AdvancedCode 136 — 7y

3 answers

Log in to vote
1
Answered by 7 years ago

Hi!

The UserInputService is a service class that must be obtained with GetService(). Otherwise this service will not exist in the DataModel.

01local Player = game.Players.LocalPlayer
02local Mouse = Player:GetMouse()
03local Gui = game.StarterGui
04local Main = Gui.DevMenu.MainFrame
05 
06if Player.Name == "AdvancedCode" then
07game:GetService("UserInputService").InputBegan:Connect(function(input,chat)
08if 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)
16end

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.

0
Afraid this does not work, still. AdvancedCode 136 — 7y
0
You should be using PlayerGui, not StarterGui. PlayerGui is where GUI's get cloned from the StarterGui to a player. Precisionly 103 — 7y
0
Not a all. If I did that, it would result in an error silly. AdvancedCode 136 — 7y
0
He's right though. PlayerGui is where the GUI is inside the player. StarterGui is just the place that holds the GUI for when a new player joins. You're getting an error for some other reason. SkeletalReality 590 — 7y
View all comments (2 more)
0
It is not a member of datamodel. AdvancedCode 136 — 7y
0
Nvm I fixed it. AdvancedCode 136 — 7y
Ad
Log in to vote
0
Answered by 7 years ago
Edited 7 years ago

You should be using PlayerGui, not StarterGui. PlayerGui is where GUI's get cloned from the StarterGui to a player.

01local Player = game.Players.LocalPlayer
02local Mouse = Player:GetMouse()
03local Gui = Player.PlayerGui
04local Main = Gui.DevMenu.MainFrame
05 
06if Player.Name == "AdvancedCode" then
07game:GetService("UserInputService").InputBegan:Connect(function(input,chat)
08if 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)
16end
Log in to vote
-1
Answered by 7 years ago

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

1Gui = Player.PlayerGui

That should help!

0
Yeah, no. AdvancedCode 136 — 7y
0
._. Just follow my instructions. It might be the whole reason it doesnt work. XxJRushxX 22 — 7y

Answer this question