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

how can I use keydown to pop up a gui?

Asked by 10 years ago

I want to make a gui that shows the rules and that etc. But im very confused on this. I know the keydown function (which I cant show at the moment because im using a phone.). But what script should I use for the --code part?

1 answer

Log in to vote
0
Answered by
nilVector 812 Moderation Voter
10 years ago

This should be in a LocalScript:

wait()

local player = game.Players.LocalPlayer
local mouse = player:GetMouse()
local gui = script.Parent --Wherever your GUI is located (This is just for the example)

mouse.KeyDown:connect(function(key)
    if key:lower() == "q" --Just an example key, change to whatever you want
        if gui.Visible == true then
            gui.Visible = false --Makes GUI invisible
        else
            gui.Visible = true --Makes GUI visible
        end
    end
end)

Likewise, if you want to use a special key such as "F4", you'd have to use:

if key:byte() == 29 then
    --Code
end

You can find an entire list of the codes for special characters here:

http://wiki.roblox.com/index.php?title=Taking_keyboard_input

0
thanks! legoson7 70 — 10y
Ad

Answer this question