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

How to open a UI when a key is pressed? (SOLVED BY KINGDOM5)

Asked by 5 years ago
Edited 5 years ago

I am trying to make a command bar so you can type commands and run stuff even though you are not the owners. I already got the tween function down but I wanna know how to do the key bind. I used this code

game:service'UserInputService'.InputBegan:connect(function(inputObject, gameProcessedEvent)
    if (inputObject.KeyCode=='W') then
    print'Hi.';
    end;
    end);

1 answer

Log in to vote
0
Answered by
blockmask 374 Moderation Voter
5 years ago

Here you go, also your script is full of deprecated ways my man

local UIS = game:GetService("UserInputService")
local Player = game.Players.LocalPlayer

function InputBegan(input, typing)
    if (input.KeyCode == Enum.KeyCode.W) and not typing then
        GuiObject:Clone().Parent = Player:WaitForChild("PlayerGui")
    end
end

UIS.InputBgan:Connect(InputBegan)

And if you're looking forward to using a more unique way, I recommend learning about ContextActionService

0
Nevermind, just realised this was answerd blockmask 374 — 5y
Ad

Answer this question