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

I need help with scripting, can yall help me? i need help with detecting a keyboard button pressed

yea so i need help sorry for the title i am still learning scripting i am a noob at it how do i detect a keyboard key pressed?

1 comment

0

Input service.

4 answers

✓ Accepted answer

You can use the UserInputService to detect when a key is pressed. For example:

local userinputservice = game:GetService("UserInputService")

userinputservice.InputBegan:Connect(function(key) -- when key is pressed
	if key.KeyCode == Enum.KeyCode.Q then -- if key is *x* then...
		--CODE
	end
end)

You would use UserInputService to detect keys being pressed down.

local InputService = game:GetService('UserInputService') -- Gets the input service

InputService.InputBegan:Connect(function(key) -- InputBegan runs when a key is pressed and the the variable 'key' will represent what was pressed
if key.KeyCode = Enum.KeyCode.TheKeyYouWant then -- Checks if the key is the one you want
--Code here
	end
end)

If this helped you please mark it as answered :D

welp now i aint answering any cus i already found a MUCH shrter version

1 comment

0

but i will upvote alls yall :D

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