I have a script for my inventory GUI. it requires you to either press the Open/Close Inventory button or Press F. Below is a serverscript for the button
local frame = script.Parent.Parent.Inventory
local UserInputService = game:GetService("UserInputService")
function OpenOrClose()
if frame.Visible == false then -- Checks to see if it is open or closed
frame.Visible = true -- Opens the GUI
elseif frame.Visible == true then -- Checks to see if it is open or closed
frame.Visible = false -- Closes the GUI
end
end
script.Parent.MouseButton1Click:Connect(function()
if frame.Visible == false then
frame.Visible = true
elseif frame.Visible == true then
frame.Visible = false
end
end)
local UserInputService = game:GetService("UserInputService")
UserInputService.InputBegan:Connect(function(input,gameProcessedEvent)
if input.UserInputType == Enum.UserInputType.Keyboard then
if input.KeyCode == Enum.KeyCode.F and not gameProcessedEvent then
OpenOrClose()
end
end
end)
The button works except when I press F, it doesn't open or close. Can anyone tell me why?

2 comments
I supposedly planned for it to be E but it had the same problem so I switched to F but the problem persisted
Serer-sided Scripts do not have access to Services that are designated on the Client's device. UserInputService is only accessible from LocalScripts for obvious reasons, you should also be programming a UI in a LocalScript, as again, it is locally designated.