Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
COMMUNITY QUESTION

script or localscript that when you press b it shows you a gui?

1 answer

Use the ContextActionService or the UserInputService.

Looking at your code, you attempted a Mouse.KeyDown event, that is deprecated. Do not use it for new work.

And yes a LocalScript. The LocalScripts are on clients, and they handle user input, not the server.

If you used a server script to do this, it:

#1. Has to tell the server you pressed a button #2. The server tells your client to show the Gui #3. Lots of lag

But with a LocalScript you can simply press a button, and simply make the gui appear and completely eliminate lag time.

-- ContextActionService method
--Make sure that the Gui is in StarterGui, but the frame's Visible property is set to false.
--LocalScript inside of your ScreenGui.

function showGui()
    script.Parent.Frame.Visible = not script.Parent.Frame.Visible
end

game:GetService("ContextActionService"):BindAction("ShowGui", -- action name
 showGui, -- function bound
 false, -- create touch button which appears for only mobile players
Enum.KeyCode.B, -- variable amount of user input to make the function fire
Enum.KeyCode.E
)

UserInputService method

-- Same thing. In a LocalScript inside the ScreenGui.
-- UserInputService method

local UIS = game:GetService"UserInputService"

function showGui()
    script.Parent.Frame.Visible = not script.Parent.Frame.Visible
end

UIS.InputBegan:Connect(function(input)
    if input.KeyCode == Enum.KeyCode.B then
        showGui() 
    end
end)

This discussion is preserved as it was. New answers, comments, and votes are closed.