The goal of this script is whenever a player presses G, a frame should be visible. However, it doesn't and I can't seem to find the issue. Here's the code:
``` local frame = script.Parent:WaitForChild("Frame") local open = script.Parent.Open
function onKeyPress(inputObject, gameProcessedEvent) if inputObject.KeyCode == Enum.KeyCode.G then if open.Value == false then frame.Visible = true open.Value = true elseif open.Value == true then frame.Visible = false open.Value = false end end end
game:GetService("UserInputService").InputBegan:connect(onKeyPress) ``` Anyone found the problem?
Hey, Jxemes!
Pretty close solution here. There are a few things we can do to make this code a little bit cleaner! The most notable change is that frame.Visible is a boolean value. So, we can use the "not" operator to check if frame.Visible is a "falsey" value, or anything that pretty much equals false. This eliminates two extra if statements!
It'll basically just say, whatever frame.Visible is, true or false, make it the opposite.
Edit: Had a lot of random double spaces.
```lua local UIS = game:GetService('UserInputService'); local frame = script.Parent:WaitForChild('Frame');
UIS.InputBegan:Connect(function(inputObject, gameProcessedEvent) if inputObject.UserInputType == Enum.UserInputType.Keyboard then if inputObject.KeyCode == Enum.KeyCode.G then frame.Visible = not frame.Visible; end end end) ```
local frame = script.Parent:WaitForChild("Frame") local UIS = game:GetService("UserInputService") -- Gets the service for input UIS.InputBegan:Connect(function(InputObject,gameProcessedEvent) -- When input begins then if InputObject.KeyCode = Enum.KeyCode.G then if frame.Visible == false then -- If the frame is closed then frame.Visible = true -- Open it. elseif frame.Visible == true then -- If the frame is open then frame.Visible = false -- Close it. end end end) --Hope this helps