How to get a already pressed key

Ahoy Everyone, I’m trying to figure out how to press the same key of an already pressed key in the userinputservice. I have a simple script right here

local UserInputService = game:GetService("UserInputService")
local player = game.Players.LocalPlayer
local emoteWheel = game.StarterGui.EmoteWheel
emoteWheel.Parent = player.PlayerGui

local animation = script.Emotes.Laugh

UserInputService.InputBegan:Connect(function(I, E)
	
	if I.KeyCode == Enum.KeyCode.G then
		emoteWheel.Enabled = true
		end
end)

Hey there! I’m confused as to what you are trying to accomplish. Would you mind elaborating what functionality you are trying to make work with your UI using the key presses?

1 Like

If you’re trying to get the same key to have 2 functions you could use a simple boolean and if statement. Similar to a debounce.

I want to use the keycode.g thing again but I do not know how to do it I know theres a way

What do you want to use the G button for? To close the UI? For a completely different function?

Just to close the ui limit TAB

UserInputService | GetKeysPressed - Roblox Creator Hub

UserInputService | IsKeyDown - Roblox Creator Hub

1 Like

^ garlic has the correct solution you are asking for. However, I think (perhaps incorrectly) that what you are trying to do is press G to open Ui, then press G again to close it. If this is the case, you could do emoteWheel.Enabled = not emoteWheel.Enabled

2 Likes

I totally forgot about this “not” thing, I used to do this all the time with GUI

2 Likes

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.