Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
✓ ANSWER ACCEPTED

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

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!

4 comments

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.

0

Not the problem.

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.

0

Yeah, that didn't work either.

3 answers

✓ Accepted answer

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.

6 comments

0

Afraid this does not work, still.

0

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

0

Not a all. If I did that, it would result in an error silly.

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.

0

It is not a member of datamodel.

0

Nvm I fixed it.

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!

2 comments

0

Yeah, no.

0

._. Just follow my instructions. It might be the whole reason it doesnt work.

This discussion is preserved as it was. New answers, comments, and votes are closed.