I have a variable called 'currentLetter' which is used earlier on in my code to get the first letter of string. I also have a textbox which I want to detect whether or not the letter I have typed is in the variable. I have done this with userInputService and using InputBegan but it doesn't seem to be working.
game:GetService("UserInputService").InputBegan:connect(function(inputObject, gameProcessedEvent) if inputObject.KeyCode == currentLetter then print("Hello") end end)
Any help would be very much appreciated. Thanks
The inputObject isn't a letter/string. It is an Enum. String keys were deprecated a long time ago.
The enum for keyboard keys are Enum.inputObject.KeyCode."INSERT KEY HERE"
Here is your script fixed:
game:GetService("UserInputService").InputBegan:Connect(function(inputObject, gameProcessedEvent) if inputObject.KeyCode == Enum.KeyCode.B then print("Hello") end end)
Note: I put the key B just to fill in the script, however, you can change it to your own liking like Enum.KeyCode.F and so on. I also swapped :Connect() with :connect() because :connect is deprecated and not supported.
Here's a link to the Enum keycode: https://developer.roblox.com/en-us/api-reference/enum/KeyCode