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

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!

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.

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.

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.

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

Gui = 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