I tried to make my GUI open on key instead of on click but for some reason it’s not working. Can anyone tell me what I did wrong?
Code
local UIS = game:GetService("UserInputService")
local Key = Enum.KeyCode.H
UIS.InputBegan:connect(function(Key,GPE)
if not GPE then
if Key.KeyCode == Key then
if script.Parent.Parent.Frame.Visible == false then
script.Parent.Text = "Close"
script.Parent.Parent.Frame.Visible = true
else
script.Parent.Text = "Store"
script.Parent.Parent.Frame.Visible = false
end
end
end
end)
You should capitalise connect like :Connect(), as the capitalised version is deprecated and may not work properly.
Also try using prints to see where your code gets to.
Finally I recommend fixing up your formatting so you can read it easily:
local UIS = game:GetService("UserInputService")
local Key = Enum.KeyCode.H
UIS.InputBegan:connect(function(Key,GPE)
if not GPE then
if Key.KeyCode == Key then
if script.Parent.Parent.Frame.Visible == false then
script.Parent.Text = "Close"
script.Parent.Parent.Frame.Visible = true
else
script.Parent.Text = "Store"
script.Parent.Parent.Frame.Visible = false
end
end
end
end)
You should just rename the Key in the parameter to something like Input, anything but Key, because it was referenced before, and when the input begins, it’ll think you’re referencing to the variable, not the parameter.
local UIS = game:GetService("UserInputService")
local Key = Enum.KeyCode.H
UIS.InputBegan:connect(function(Input,GPE)
if not GPE then
if Key.KeyCode == Input then
if script.Parent.Parent.Frame.Visible == false then
script.Parent.Text = "Close"
script.Parent.Parent.Frame.Visible = true
else
script.Parent.Text = "Store"
script.Parent.Parent.Frame.Visible = false
end
end
end
end)
Like that?
local UIS = game:GetService("UserInputService")
local Key = Enum.KeyCode.H
UIS.InputBegan:connect(function(Input,GPE)
if not GPE then
if Input.KeyCode == Key then
if script.Parent.Parent.Frame.Visible == false then
script.Parent.Text = "Close"
script.Parent.Parent.Frame.Visible = true
else
script.Parent.Text = "Store"
script.Parent.Parent.Frame.Visible = false
end
end
end
end)