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?
If i'm correct you need to set the Gui as the Player Gui.
I hope you know how to do that, before asking how to do that if you don't know search on google first for some tutorials.
If not comment down below and I'll do my best to help.
The only possible way that I can see why your code doesn't work is that "UserInputService" only works in Localscripts. Most likely, you've written your code in a Serverscript. If this doesn't work, well then I don't know.