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

Why isn't this GUI bind working?

Asked by 7 years ago
Edited 7 years ago
local screenGui = Instance.new("ScreenGui")
screenGui.Parent = script.Parent

local textLabel = Instance.new("TextLabel")
textLabel.Parent = screenGui
textLabel.Position = UDim2.new(0, 0, 0, 0)
textLabel.Size = UDim2.new(0, 200, 0, 180)
textLabel.BackgroundColor3 = BrickColor.Green().Color
textLabel.TextXAlignment = 0
textLabel.TextYAlignment = 0
textLabel.Font = 10
textLabel.FontSize = 5
textLabel.Text = ""
textLabel.Visible = false

local textBox = Instance.new("TextBox")
textBox.Parent = screenGui
textBox.Position = UDim2.new(0, 0, 0, 180)
textBox.Size = UDim2.new(0, 200, 0, 20)
textBox.BackgroundColor3 = BrickColor.Green().Color
textBox.TextXAlignment = 0
textBox.TextYAlignment = 1
textBox.Font = 10
textBox.FontSize = 5
textBox.Text = ""
textBox.Visible = false

function onKeyPress(inputObject, gameProcessedEvent)
    if inputObject.KeyCode == Enum.KeyCode.Tilde then
        textLabel.Visible = true
        textBox.Visible = true
    end
end
game:GetService("UserInputService").InputBegan:connect(onKeyPress)

Everything except for the final paragraph of code is working. Does anyone know what the problem is? Thank you!

EDIT: I've figured out that the tilde is actually the thing causing the problem, not the other commands.

0
Read this: http://wiki.roblox.com/index.php?title=Keyboard_input and read the section on UserInputService Gey4Jesus69 2705 — 7y
0
I already did, that's where I got that code from. I just edited it slightly. AvatarAang400 35 — 7y
0
Can you try print(inputObject.KeyCode.Value) prior to the if statement and tell us what is produced in the output? M39a9am3R 3210 — 7y
0
It say "Players.Player1.PlayerGui.GoldSrcBx - StarterGui:46: attempt to index global 'inputObject' (a nil value)" AvatarAang400 35 — 7y

Answer this question