Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

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

Asked by 6 years ago
Edited 6 years ago

I made this script

local guinamehere = Workspace.guinamehere local player = game.Players.LocalPlayer

script.Parent.(Key:lower() == "e") then:connect(function() guinamehere:Clone().Parent = player.PlayerGui end)

it wont work. can somebody help me?

0
Needs to be in a code block... BunnyFilms1 297 — 6y
0
whats a codeblock yogamer13294456 13 — 6y

1 answer

Log in to vote
0
Answered by 6 years ago
Edited 6 years ago

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)
Ad

Answer this question